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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with variables and actionscript

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
hi evryone,

i have 5 buttons on a menu and when someone clicks them i'd like it to transfer its name to a variable and then have an action checking the variable and if it is equal to button1 it shows button1 movie clip etc etc etc.

so far, i have the variable all set up and working but when i try and add more buttons to the actionscript like this: it doesnt work properly and loads the first movieclip all the time.

if (var="button1") {
gotoAndPlay (76);
} else if (var="button2") {
gotoAndPlay (78);
} else if (var="button3") {
gotoAndPlay (80);
}

where am i going wrong?? and also, is there a better way of showing movie clips from the library (not seperate swf's) in the movie instead of putting them all on the timeline and using gotoAndPlay?

Thanks.
 
Try setting a global variable on the load part of your movie...
it's something like
set (Variable name, Attribute)
Then you should be able to set it anywhere, but make sure if your calling it from another movie, to call _root.variablename Also, make sure your not using any reserved names...such as var (I think that's a reserved name)...use something like "Section" as a variable.
 
Assuming the code you present is exactly as appears in your action script then you should be checking for equality with double '='
== is for equality test
= is for assignment
The code you have submitted in your question will assign "button1" to the value of var then test for true (nothing to do with var or button1 now, it's just looking for 'not false') which it will get - thus falling into your first bace set.

Should read:
Code:
if (var=="button1") {
    gotoAndPlay (76);
} else if (var=="button2") {
etc

scope and visibility of var is another thing to check for now since Flash's action script is so loosely typed.

hth
scalp
 
If you want, I could send you the source code to the same problem I was having, I got it all fixed...

What I was trying to do was get an animation to play, then set a variable so once the animation played, it jumped to whatever scene I needed, just mail me at WHITETLG3R@aol.com if you want to take a look at it.
 
what is the easiest way to send a variable from one swf file to another.

Is it to use get which i believe will append it to the end of the file name like so filename.swf?variablename but then how do i retrieve it in the second movie

What i've got so far is 2 movies each embedded in its own html file. I want to send a variable from the first movie to the other movie?
 
DeepBlerg, to answer your second question...

"is there a better way of showing movie clips from the library (not seperate swf's) in the movie instead of putting them all on the timeline and using gotoAndPlay?"

you might try a couple of different things...

Place your clips on the stage as normal but instead of putting them in a specific frame place them in their own layer, loading right at the start of the main movie. Use something like -

onClipEvent(load){
_visibility=false;
}


to make the clip invisible initially, then, when you want it to be seen set the _visibility property to "true", just target the clip by using its instance name e.g. if it was launched from a button you could have..

on(release){
clipName._visibility=true;
clipName.gotoAndPlay(2);//or whatever
}


I know that it seems like a long way around the problem but I find that it makes things easier to debug if you know where everything is at the start of your movie: there's nothing worse than searching for a load of clips which are scattered throughout a hundred odd frames when something goes wrong. The other benefit of this approach is that it gets you closer to the idea of the "one frame" movie where things are more object oriented. We might get ActionScript recognised as a "proper" language yet ;-)

Another option would be to use the "attachMovie" method of the MovieClip object which basically calls the clip you want from the library at runtime but this can be a little trickier and isn't the best option if you're mainly working in the _root level of your movie.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top