Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Question from beginner: Problem with variables 2

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
Hello,
I have the following problem working with Flash 5,
I don't quit now how exactely I make a global variable.
and how do I make a variable declaration specific to a movieclip AND initialize it only once when the clip is created (like a private variable in C++ and its constructor)
Why do I want that ?
I want to make a bouncing ball, so I want to keep the vars left and up to check where my ball is going. Then when it reaches an end,it must reverse its direction.

thnx. Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
what i do is this.

for global variables:

i create a layer and name it variables. then i create dynamic text boxes in that layer, name them accordingly then put values in them. I also make sure that the keyframe in this layer lasts to the end frame of this flash movie.

when i refer to this variables from a movie i just write

_root.variableName

for variables to be used by a movie clip:

i just do the same but i do it within that movie clip. so when i refer to them, i refer to them by name.

when i need to access variables from within other movie clips on the main timeline, i use _root.MovieClipName.variableName.


that's it. i hope it wasnt that mind boggling, hehehe

biggie
 
Thnx for the reply but...
you've got to be kidding me... you mean I have to make a textfield just to have a global variable ?
and how do you make global arrays then ?
Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
I've allways used _level0.my_var = value; without any problem! It can be set or checked from anywhere, even from loaded movies on other levels.
To check it's content, when testing in the application, simply use a trace action:
trace(_level0.my_var);

Regards,

new.gif
 
Hey thanks guys!
Its only my first week in flash and this was an annoying problem!
I'll give you both a star,guess bignewbie has also learned something today :) Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
euch.... I presumed the _level thing would work, but it doesn't...
Where do you declare your vars ? or does it not matter ?
Say you have a var _level0.number=5;
can I do then var other=number ? or do I have to do other=_level0.number ?
thnx for the "trace" thing, I didn't knew that either :) Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
You don't have to use var in front of setting a variable, this only will do:

_level0.number1 = 5;
_level0.number2 = 10;
_level0.my_var1 = "Hello ";
_level0.my_var2 = "World!";
_level0.my_othervar = false; // = 0

Etc... Etc...

As for the trace trick, it's also very useful, when you're looking for the correct path of a movie clip, for instance!
In the first frame of that movie clip, you simply add a trace(this);, and the path to that movie clip will then be outputed in the output window. Regards,

new.gif
 
thnx oldnewbie,
you wouldn't happen to know the answer to my new question
you one can get the width and height of the playing movie in actionscript would you ? Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
*shocked expression*

Old!! I am shocked and horrified! After all, if everyone agreed all the time, ours would be a rather dull existence ;)
 
Talk about your's! Mine is fine! Pollyfilla is the best! Regards,

new.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top