PDA

View Full Version : Variable help


Echoblade
02-16-2003, 03:18 AM
Hello all, what I want to know is how to create a variable that my entire Flash Movie will use. It contains a "current state" value. It will be changed from another MC(menu). I've done some testing to figure it out, but it won't retain when I change the value of this variable. Any help would be great. and answer any questions to get this thing solved.

EchoBlade

Esquared
02-16-2003, 03:30 AM
Any variable defined on the _root level (main timeline) is considered locally global. If you are attempting to alter this variable from another location other than _root (ie. inside a movie clip, etc.) you can access it by using the path _root.variable. Without the _root, you will create a NEW variable with the SAME name that only has the scope of the mc timeline it is defined in, which is what you seem to be doing. Hope that helps!

CyanBlue
02-16-2003, 04:04 AM
Howdy...

Also, there is _global you can use for that matter if you use FMX... Just thought that I'd let you know... :)

Echoblade
02-16-2003, 04:09 AM
This is what I have done so far

on the _root Time Line I have a dynamic text field (text_1) and this code on one layer.

var_1 = "One";
MC = _root.attachMovie("mc_1","mc_1_", 1 );
text_1.text = var_1;

and I have another Text field(text_2) and this code on one layer in my MC

_root.var_1 = "Two";
text_2.text = var_1;

When I tested it, all I saw was "One", the text fields arn't over lapped. I'm probably making a really stupid mistake so hopefully it's easy to fix

Esquared
02-16-2003, 04:41 AM
The same issue applies for your textbox. text_2 is on the _root timeline, so your very last line of code there should be _root.text_2.text = _root.var_1.

(OR, since I can't tell from what you typed...if your text_2 is IN the movie clip itself, you just need text_2.text = _root.var_1. Though, if this is the case, I don't see the need for the _root variable at all in the example you've given.)

Perhaps you should check out the pathing tutorials on this site to get a better idea of what's going on there. I believe there are several different levels of pathing tutorials, in fact.

Good luck.

Echoblade
02-16-2003, 05:19 AM
Thanks for the help, I kinda understand what's going. I've read all the path tutorials I can find. What I know need to find is an article about syntax compling, cause, I got my test movie to print both "One" and "Two" but why does it print "One" when the print to text field code is after the MC call and the MC changes the variable value /shrug. But thanks again.

EchoBlade

Esquared
02-16-2003, 05:58 AM
Sorry I'm not quite understanding what you mean. If you can't figure it out you could post the .fla...

Echoblade
02-16-2003, 06:05 AM
here is another example of my confussion

Main Timeline:Layer 1:Frame 1
_global.var_1 = "One";
MC1 = this.attachMovie("mc_1","mc_1_", 1 );
text_1.text = var_1;
mc_1 Timeline:Layer 1:Frame 1
var_1 = "Two";
MC2 = this.attachMovie("mc_2","mc_2_", 2 );
text_2.text = var_1;
mc_2 Timeline:Layer 1:Frame 1
text_3.text = var_1;

each timeline has its own text field and this is the output
text_1 = "One"
text_2 = "Two"
text_3 = "One"

If I change from using a _global command to using the full path commands

Main Timeline:Layer 1:Frame 1
var_1 = "One";
MC1 = this.attachMovie("mc_1","mc_1_", 1 );
text_1.text = var_1;
mc_1 Timeline:Layer 1:Frame 1
_parent.var_1 = "Two";
MC2 = this.attachMovie("mc_2","mc_2_", 2 );
text_2.text = _parent.var_1;
mc_2 Timeline:Layer 1:Frame 1
text_3.text = _parent._parent.var_1;
this is what I get.
text_1 = "One"
text_2 = "Two"
text_3 = "Two"

now it still doesn't work like I want it. my intent is to have all the text fields say "Two" cause I call the MC's before I tell the text field anything.

Esquared
02-16-2003, 06:23 AM
OK....now I'm confused, because I don't get EITHER of the outputs you said, but I DO get what it looks like it should be outputting....One, Two, Three...
What you have in the file you sent does the following:

1. sets the _root.var_1 to "One"
2. attaches mc_1
3. sets the text of text_1 to _root.var_1, or "One"

4. sets the _root.var_1 to "Two"
5. attaches mc_2
6. sets the text of text_2 to the NEW value of _root.var_1 (via line 4), or "Two"

7. sets the _root.var_1 to "Three"
8. sets the text of text_3 to the NEWEST value of _root.var_1 (via line 7), or "Three"

So two questions. What is it that's not right, because your code is working as you have it. And why do you need the root variable at all...since the calls to it are all made from within the movie clip you want to set the text...???

I think you need to better explain your application of this movie before I can help.

Echoblade
02-16-2003, 06:42 AM
What I'm trying to do, is create a movie with a menu. The buttons on the menu change what is displayed in the center. the menu buttons read:
News
Personnel
Pics
Sounds
ect..

So as I click a button, it loads the approprate MC. My menu is a MC called "menu" So my idea was when the button was pushed, it changed a variable, lets call it "current_state" to "news","personnel", or .... depending on the button. then all I have to do is say "_root.attachMovie( current_state, "stuff_", 1);" and the MC I want is loaded.
Now I might be looking at the problem the wrong and just creating more work than I need. but I'm pretty new to actionscript
but I have some C++ experence. I hope this clears up things I'm not that good at explaining my ideas

Esquared
02-16-2003, 06:59 AM
OK...now that I know what you're doing I can actaully help out here. Let's start from scratch...

First let me offer a few options...

1. Do it your way...but I STILL don't see any need for the root variable. I use this approach sometimes, but only when I need to know what page is currently open for some other reason. If all you need to do is attach the right one, you can do it explicitly. I can show you how to do it explisitly or with the variable.

2. Rather than attaching all of the movie clips separately, just have one main movie clip that is always on the stage, which has an empty frame in frame 1 with a stop() action, and then has a movie clip for each page on each consecutive frame. To "open" your pages, you could just tell this movie clip to gotoAndStop(page).

3. If it is important that you're actually loading these pages onto the stage from elsewhere, you should really learn how to to use loadMovie(), which lets you actuall load external .swfs, not just stuff from the library. This is really only useful when you have larger environments with lots of content that needs to be changed regularly, such as websites.

Let me know what the menu is for, and which of those sound reasonable, and I can tell you more.

Echoblade
02-16-2003, 04:57 PM
This is my site that I'm trying to turn all flash drumline.astate.edu. I will be using XML to load the content for easy updating. Aslo the pics/sounds will be load dynamically to reduce the size of the movie. Not sure the best method, but the first one sounds good

EchoBlade

Esquared
02-16-2003, 05:26 PM
OK-

Well here's my opinion. If you're trying to set this site up so that content is only loaded when it is needed, to save bandwidth, you should opt for the last way. Basically, you'll create a main menu and intro page that loads when the user arrives at the site. Clicking on the menu buttons will then load external .swfs that are published as self contained movies. This means first of all that if you want to edit part of your site, you only edit the page you want. You don't have to open up the swf with the ENTIRE site inside it. It just makes development more efficient. Also, it lets you create little loading bars for each section, and then they'll only have to wait to load the sections they actually choose to look at.

Your first way would work for some applications, but basically I son't see the point in loading the pages from the timeline, since they'll still have to load them all in from the start anyway, even if they don't see them right away. Just another note on that idea: if you plan to create a loading bar for the main page, ANYTHING that you click "Export for actionscript" has to be loaded BEFORE the movie will even start...in other words, before your preloader even pops up. I try to minimise that time, so users don't think that the site froze.

So the long and short of it is, go check out the loadMovie() tutorials and see what you come up with. Once you've done that, feel free to post again and we can help you out, but it's easier for us to help if you have a background idea of what we're trying to help you do.

Good luck!