Globals?
I would like to know what method to use for this problem?
I have six buttons on-screen. Each button goes to a marker and plays an animation and reveals content. I would like that content to stay on-screen when you link to another marker to play another animation. And so forth for each button.
I am using Flash 5. What functions would I use to do this?
Thank you!
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-27-2002, 06:51 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Using Globals?
After doing some research I found that you can set global variables. Is there a way to use those to add actions to a button throughout my entire swf then? For instance, I have a movie with scenes and each has a button with the same basic code:
btn.onRollOver = function() {
stop();
}
btn.onRollOut = function() {
play();
}
Can I place this code somehow on one frame at the beginning of my code and have it apply everywhere? Thanks for taking a look.
Javascript GLOBALS
Uh, I've got a stupid javascript problem,
perhaps someone can help me:
I have to make a variable global, so that all functions can read and write
into the value:
u=500;
function A()
{
u=300;
x=0;
}
function B()
{
y=0;
document.write(u);
}
If function A is done, and then B, actually u should be 300,
but it isn't at the moment.
thanx for any help.
Globals In Flash 5?
Is there a way to create some sort of object in Flash 5 in an OOP way which would emulate some sort of global namespace?
I'm inheriting a large project where there are consistent _root references in the project.
The project needs to be delivered in Flash 5.
Is there any way to create some sort of globally accessible object or namespace so I could replace all the _root references which are scattered throughout the code.
One of the project requirements is that the code is portable.
Thanks!
[F8] OnMotionFinished And Globals
I'm trying to call something when a tween motion is finished. However it isn't working. I believe it is because the tween is being created in a function. I tried assigning global to it, but flash doesn't allow that for strict data types according to documentation. I call the glideup() function from a button. That part works, but the trace("finished") doesn't.
Here is my code:
Code:
//makes the logo glide up
function glideup() {
var yMove:Tween = new Tween(mylogo, "_y", Bounce.easeOut, mylogo._y, mylogo._y - 160, 2, true);
}
//after glideup() is finished, this is called
yMove.onMotionFinished = function() {
trace("finished");
}
Confused With Globals
Hello,
ActionScript Code:
_global.QIdtext.text = 0
_global.hello = 2
trace("hello"+hello//returns 2!)
trace("QIdtext"+QIdtext.text//returns undefined)
trace("QIdtext"+_global.QIdtext.text//returns undefined)
Why oh why am I getting undefined!? anyone know how I could get arorund this?
Thankyou!!
Globals In Crossdomain Swf's (AS2)
Hi,
I have two domains (on the same server) each of the domains contains a crossdomain xml and swf's. The swf's have System.security.allowDomain("*") set.
From 'domainOne' I start the main swf. This main swf loads (with a loader component) a swf from 'domainTwo'. So var so good.
In the main swf on 'domainOne' I have some _global functions. When I call these global functions from the second swf (from 'domainTwo') nothing happens.
My question: Is it possible to call global functions between crossdomain swf's? If so, what's the trick?
Thanks
Are Globals Really Not Global?
At different times, I set globals in my main swf and the swf that it loads, but they never see each other's global, even though they're each constanly checking.
Is it just the case that "globals" aren't really global between a swf and the swf it loads?
I've tried checking for the global by looping between 2 frames and I've also tried:
trackinterval=setInterval(trackfunction,100);
function trackfunction(){
trace("_global.gStatus);
}
In either case, I've verified that both swfs are constantly checking, because they are both constantly outputting their trace statements.
Any suggestions?
Why Don't These Globals Work?
I'm having trouble communicating globals bewteen a main swf and a loaded swf.
Someone posted code that works for them, but not for me:
In global1.swf:
stop();
_global.testValue=5;
_global.theThing="Hello there world!";
loadMovieNum("global2.swf", 10);
In global2.swf:
stop();
trace(_global.testValue);
if(_global.testValue==5){
_global.testValue+=3;
trace(_global.theThing);
}
The trace in global2.swf gives me "undefined" so the trace in the "if" statement doesn't appear at all.
Does the code work for you?
What could I be doing wrong?
Globals And Galleries
Hey Kids,
OK, here's the situation:
I have a main swf file calling another swf file into a container movie for a gallery.
The swf file being called has _root stuff on it, so I worked the _global variable on it, and everything is working fine.
Until I load it into the gallery, then the button on the loaded swf file no longer works. I think I am missing something.
code on loaded swf button:
Code:
on (press) {
myAppMain.clip.gotoAndPlay(2);
myAppMain.clip.fall.text = myAppMain.clip.nofall.text;
myAppMain.clip.nofall.text = "Dance Elements";
gotoAndStop(2);
}
and yes, the global is in the main timeline. My question is, does there have to be something in the main movie file? Here's the code on the button calling the loaded swf file:
Code:
on (release) {
loadMovie("flashwork/danceele.swf", "_parent.flash");
}
the _parent is there because the main swf file is also loaded into <i>another</i> swf file which is the real movie, but means nothing to us for this example. The container movie is called "flash".
Any help is really appreciated.
P
Are Globals Really Not Global?
At different times, I set globals in my main swf and the swf that it loads, but they never see each other's global, even though they're each constanly checking.
Is it just the case that "globals" aren't really global between a swf and the swf it loads?
I've tried checking for the global by looping between 2 frames and I've also tried:
trackinterval=setInterval(trackfunction,100);
function trackfunction(){
trace("_global.gStatus);
}
In either case, I've verified that both swfs are constantly checking, because they are both constantly outputting their trace statements.
Any suggestions?
Why Don't These Globals Work?
I'm having trouble communicating globals bewteen a main swf and a loaded swf.
Someone posted code that works for them, but not for me:
In global1.swf:
stop();
_global.testValue=5;
_global.theThing="Hello there world!";
loadMovieNum("global2.swf", 10);
In global2.swf:
stop();
trace(_global.testValue);
if(_global.testValue==5){
_global.testValue+=3;
trace(_global.theThing);
}
The trace in global2.swf gives me "undefined" so the trace in the "if" statement doesn't appear at all.
Does the code work for you?
What could I be doing wrong?
How To Change Globals Dynamically
how to change a global dynamicallyI'm working on a game that involves the loading of many SWFs ( one at a time into _level1, displacing each other) into a container mc. All these SWFs will have seven frames. I understand that I can put a 'global' variable in the first frame of the root movie and a conditional expression into the first frames of the SWFs. I've checked this out and it works. ( So in the root I have Object.prototype.whatframe = 3;,and in the first frames of the SWFs I have; if(_level0.whatframe==3){gotoAndStop(3);}else{goto AndStop(1);} )
So I am convinced that the SWFs can read and react to the global. So far so good, but as it stands all my SWFs will go to frame 3 once loaded...not very useful.
What I need to know is how to make a function that will dynamically adjust the value of whatframe, so that whatframe retains its global characteristics.
Any help or hint from anyone on the planet would be most appreciated
If & Else, Globals. Problems With Direction. Please Help Me :(
I have a deadline for a computer prototype (i know i should have done it earlier) in for tomorrow and im having major difficulties with the shooting characters. I really need some help...
Basicaly iv tried to script a 2 player game where you jump about with your friend and blast each other about with some kinda of weapon. The problem is i cant get the direction of the bullets to correspond to the direction of the character.
The thinking behind my system was to script it so when the character pressed LEFT _global.char1left=1; was set, and when he pressed RIGHT _global.char1left=0; was set. Then the script for my bullets was on a
if(_global.char1left=1){
make these changes
}else{
do this instead
}
See? Well, it doesnt work. The theory as far as i can tell is sound i just cant get it to work. Ill post a link to my source if anyone is interested to look into it. But the main code i shall put in here:
http://www31.brinkster.com/jakifer/m...revised%29.fla
Please dont just download for the hell of it, i have very little bandwidth.
Bullet code:
code: onClipEvent (load) {
if (_global.char1left=0) {
bullet1MoveSpeed = 20;
this._x = _root.char1._x+32;
this._y = _root.char1._y-31;
} else {
bullet1MoveSpeed = 20;
this._x = _root.char1._x-32;
this._y = _root.char1._y-31;
}
}
onClipEvent (enterFrame) {
if (_global.char1left=1) {
this._x -= bullet1MoveSpeed;
this.setProperty(_rotation=180);
} else {
this._x += bullet1MoveSpeed;
}
}
onClipEvent (enterFrame) {
if (this._x>900) {
this.removeMovieClip();
("right hand shot removed");
}
if (this._x<0) {
this.removeMovieClip();
trace("left hand shot removed");
}
if (_root.char2.hitTest(_x, _y, true)) {
this.removeMovieClip;
}
}
And the character code is:
code: onClipEvent (load) {
bullet1Speed = 10;
_root.bullet1._visible = false;
bullet1Counter = 1;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.CONTROL)) {
bullet1Counter++;
_root.bullet1.duplicateMovieClip("bullet1"+bullet1 Counter, bullet1Counter);
_root["bullet1"+bullet1Counter]._visible = true;
}
}
onClipEvent (load) {
gravity = 15;
scale = _xscale;
walkSpeed = 10;
maxjump = 10;
}
onClipEvent (enterFrame) {
if (air == true) {
_y += gravity;
state = 3;
}
if (Key.isDown(Key.LEFT) && !_root.leftbound.hitTest(_x, _y, true)) {
_x -= walkSpeed;
_xscale = -scale;
_global.char1left = 1;
trace("char1left = "+_global.char1left);
}
if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
_xscale = scale;
_global.char1left = 0;
trace("char1left = "+_global.char1left);
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.UP)) {
jumpcount += 1;
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
onClipEvent (keyUp) {
if (Key.getCode() == 83) {
jump = false;
}
}
PLEASE PLEASE PLEASE HELP ME!
[CS3+AS2] Globals Undefined In Some Instances But Ok Others?
I'm very confused at the moment...
I have a Flash movie that grabs data from a DB and stores all of it into a bunch of _global's. I was starting to have a few problems with loops and conditions so I started tracing the variables I was using. Tracing the same variable 4 times gave me 3 correct results and one undefined. Spelling was correct as I copy pasted the trace() from one instance to another.
For example:
trace(_global.varName); in _root.clip01.clip02 returned the correct result.
_root.clip03 returned undefined.
_root.clip04 was correct.
_root.clip05 was correct as well.
So apparently my variable can be read in certain instances but not others. I'm still kinda new to Flash, so I'm not sure how to approach this problem. If it helps any, so far it seems that every new instance I add to my movie has a hard time reading the _global's, but old stuff that's been in there a while seems unaffected.
Is there a better way of storing variables returned from a PHP file for use across an entire movie than this:
Code:
myVars = new LoadVars();
myVars.onLoad = function(success){
if(success){
// Set Variables
_global.varNameA = this.phpVarA.split(",");
_global.varNameB = this.phpVarB.split(",");
_global.varNameC = this.phpVarC.split(",");
}
}
myVars.load("http://www.myurl.com/phpscript.php");
Thanks in advance!
[FMX2004] Actionscrpt Php Globals=on/off
im not very into php thats why im wondering this question. If the server uses globals=off what does it mean for the actionscript code when u loadVariables from php on that server?
-MZA
Are Globals Resource-intensive?
Im using maby 100-150 globals for different stuff in my project (some are strings of a couple of words, so they can be pretty big). Im wondering if this is a cause of concern prestanda-wise?
[AS2 OOP] Addicted To Globals What Are The Alternatives?
Hi everyone! My name is Matthew and I am a recovering globals addict.
I would so much like to avoid the classic problems of using globals and anything like them. By globals I mean objects and other properties which any code anywhere can easily access reliably. I know that they can bloat and be hard to keep track of; they can get corrupted from anywhere in code; they reduce reusability; and so on.
In my game app I have some “pseudoglobal” values and objects which are needed for read/write by many objects at many levels. For example:
--playfield width
--objects that hold data about "person" entities
--the interface mode
--system options
--common sound effects
--and so on
I have some classes, the names of which hopefully make their basic function obvious:
--Room (of which there can be many instances)
--Person (ditto)
--Menu
--Tooltip
--VideoStream
--And so on
Since the _global keyword is being deprecated in AS3 I thought I was partially redeeming myself by storing the "pseudoglobals" described above as static properties of a class (such as playfield width), or as members of a static array (the people objects). But I've been told that it's not really weaning me off of _global. Kind of like getting off heroin but hooked on methadone. A few related questions I’d then have are the following and I’d really appreciate any thoughts:
1) If I use getter/setter functions for these statics, thereby enforcing a bit more security and allowing easy tracing of writes to them, is that any better?
2) If not, what are my alternatives to using the statics I describe above? They seem to be the following, all of which seem in my clouded mind to be equally hazardous or clumsy:
--a) Code each one down as far into single classes as possible, so some of them can become accessible through this.<property> and _parent.<property>. But it seems many of them just won’t push down; they are needed by at least two major classes.
--b) Stamp onto all instances of everything a pointer to a “God” object to which these pseudoglobals are connected. So access is done through this.godObj.<property>. That seems like a lot of instance overhead and a lot of stamping, any one of which can be malformed.
--c) On instance creation, pass along these pseudoglobals and have the constructor store them into local private vars, making each class access it through this.<property>. That seems like a lot of parameters to pass.
--d) Have all instances use “_parent”, “_parent._parent”, and so on, to walk up the chain to the game instance that owns it, in which these pseudoglobals are properties. That seems like it will break a lot if I move instances deeper or shallower in my object chains.
--e) Make all my classes sub- or sub-sub-classes of the Game class and let inheritance expose these pseudoglobals, which are properties of the Game class, to all subclasses. So access is done just through <inherited property> or super.<inherited property>. That seems like it may needlessly deepen the subclass chains and make it more puzzling to figure out where the value is coming from.
3) I think I understand Singleton: I assure that there is only one instance of Game, and therefore I always can refer to its instance confident that it’s the only one. Using Flash’s F1 Singleton example, I could use gameObj = Game.getInstance() and then access gameObj.<property or method>. If I use Singleton, can I now use gameObj safely as the home of the pseudoglobals I describe above? Or is that just as bad as using statics?
I appreciate the help I've gotten here so far. I feel like I am really getting somewhere!
Trouble With Globals Variables
I am having trouble with my globals and I am not seeing whats wrong. I have attached my fla. In the first frame of my movie I declare some global variables to false. I also have two buttons each with code to trace the globals and to jump to a different frame. When I jump to those frames I set the variables from false to true, but when I rollover my button to trace the variable, it doesn't seems to be getting set. I am not sure what I am doing wrong. Would appericate any help.
[FMX2004] Actionscrpt Php Globals=on/off
im not very into php thats why im wondering this question. If the server uses globals=off what does it mean for the actionscript code when u loadVariables from php on that server?
-MZA
Are Globals Resource-intensive?
Im using maby 100-150 globals for different stuff in my project (some are strings of a couple of words, so they can be pretty big). Im wondering if this is a cause of concern prestanda-wise?
Loading Vars And Globals, Help
Hi!
I'm loading vars from a txt file and works!
aV=new LoadVars();
aV.load("mix1.txt");
aV.onLoad=function(){
test1=aV.variable1;
test2=aV.variable2;
test3=aV.variable3;
test4=aV.variable4;
test5=aV.variable5;
}
My problem is I want to make test1,test2,... global variables, someone knows how could i do it?
AttchMovie MC Aren't Updating Globals
Hi. I have a MC that is draggable. When placed over the right drop target it calls attachMovie and calls another copyof itself from the library with a new name (offest by 1) and a new layer (50 layers higher). So, I have code in the on (press) that increments a global variable called "clipNum" by 1 using ++clipNum. (I declared clipNum in the first frame with a call to clipNum = 0; which I believe default creates a global variable.
Okay, now the problem is that when I drag one of the "cloned" movies they only increment the global "clipNum" on the first drag. As in if clipNum is at 2 and I drag a clone, it'll become 3, but on the next drag and the next it'll stay at 3 no matter how many times I drag it. Only after dragging the original clip twice do I get the incremental steps again. What is going on here? Is there some limit to attachMovie created clips to running code? I have carefully crafted layering based on this variable getting updated every time a clip is dragged, so this is really putting a monkey wrench in the works. Any help would be greatly appreciated. Thanks.
[F8] Globals Only Work When Testing Movie In Flash
Hi,
I'm developing a program that is compiled of a lot of different files. I have a global array created by a file loaded into the 3rd level (just using loadMovie at this point). Then I have assets in a file loaded into the 1st level that use data from that global array.
When I test the flash application inside of flash (using control->test movie) it works fine, but when I go to play it in the Stand Alone Flash player or in the browser it no longer works, the global variable appears undefined to the other levels. Any idea why this is?
I know that the global is being created and populated correctly because I set up a text box on level3 and level0, level3 shows the correct array and level0 shows undefined. Any ideas?
Crossdomain Globals... Big Problem With Class Static Variables
Hi,
Nobody knows this before having spent several hours pulling their hair: two swf loaded from two different domains don't share the same _global object. This is not mentionned in the "Flash Player Security functions" section of the doc.
This restriction seems to impact on class static variables: as far as I remember, when compiling a swf, as2 is converted to as1 and classes are transformed into functions prototypes and stored into objects that recreate the class path. These objects are stored into the _global object, isn't it? (At least this is what you see when watching into the _global object using the debugger).
For example the class com.mycompany.MyClass will be stored into _global.com.mycompany.MyClass
When using static variables in the class, for example myStaticVar, I assume this is stored in the same place, that is to say inside _global.com.mycompany.MyClass.myStaticVar.
Ok, so when two swf loaded from different domain use the same class, they both have, inside their own different _global object, a different _global.com.mycompany.MyClass object so the static variable held inside it can differ between the two swfs.
For example : in swf A (www.domainA.com) MyClass.myStaticVar may differ from MyClass.myStaticVar in swf B (www.domainB.com).
The attached example demonstrates it: upload domainA.swf + domainA.html on a domain and domainB.swf on a different one and access domainA/domainA.html (You'll have to set the domain string inside each fla before generating). The domainB swf doesn't find the static var value although it is set inside A. This same example works perfectly if you use the same domain as A and B.
This has huge consequences, since this means that static variables cannot be relied on when developping cross-domain websites...
Does anyone have already faced this and found an acceptable workaround?
I have personaly used this trick for a Singleton class : store the instance on _level0 wich is common to any swf loaded... I hate doing this plus it doesn't work all the time!
Any inspired advise much appreciated!
|