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

How do I use a variable to specify a frame label in goto statement?

Status
Not open for further replies.

KingDufus

Technical User
Oct 9, 2001
19
0
0
US
Hi,
I have a flash movie which contains a movie clip (named "buttons"), that contains two frame labels: "open" and "closed".
I am interested in loading variables from a text file, and then telling the movie clip to go to one of its frame labels that is defined in a variable.
I am having difficulty achieving this.

My text file is named "status.txt"
It contains the following text:
option=open

I found some info on the macromedia site and created the following script in the main timeline:

loadVariablesNum ("status.txt", 0);
gotoAndPlay ("/buttons:" & option);

This method of using a variable in a goto statement is supposed to work according to the site, but it isn't for me. Does anyone know what I'm doing wrong or if there is a better way?
I'm targeting Flash 4 players.
Thanks!

-King Dufus
 
Had to take Flash 4 out of the closet, and try to remember for 3 hours, how to program the darn thing!
Came up with the following:

Text file is the same and holds:
option=open

The loading is fairly similar:
Flash4...
Load Variables ("status.txt", 0)
Flash5...
loadVariablesNum ("status.txt", 0);

An "enter" button in Flash 4 syntax would look like this:
Code:
On (Press)
      If (option eq "open")
            Begin Tell Target ("/buttonsmc")
                  Go to and Stop ("open")
            End Tell Target
      Else
            Begin Tell Target ("/buttonsmc")
                  Go to and Play (15)
            End Tell Target
      End If
End On
The same above code imported in Flash 5 would be automatically corrected and adapted in the following manner:
Code:
on (press) {
    if (option eq "open") {
        tellTarget ("/buttonsmc") {
            gotoAndStop ("open");
        }
    } else {
        tellTarget ("/buttonsmc") {
            gotoAndPlay ("close");
        }
    }
}
And for a Flash 5 player compatibility could me more easily scripted as:
Code:
on (press) {
	if (option == "open") {
		_root.buttonsmc.gotoAndStop("open");
	} else {
		_root.buttonsmc.gotoAndStop("close");
	}
}
Regards,
and might I be blessed with your vote!
new.gif
 
A kind of typo... But really not!
Please take note that, in this situation, you can either target a frame number or a label, thus either frame 15 or frame labelled "close"!

Regards,
and might I be blessed with your vote!
new.gif
 
Hi OldNewbie,
Thanks for posting a reply. I tried the Flash 5 code, and it didn't quite work as typed. After trying a couple of things, it worked when I substituted == for the eq, so I combined your flash 5 code and your flash 5 player code. Here's what worked:

if (option == open) {
tellTarget ("/buttonsmc") {
gotoAndPlay ("open");
}

Thanks for the help!
Now, I have another question. Can I accomplish the same task without using a conditional statement? Can I substitute the actual frame label in the gotoAndPlay statement with the variable?

tellTarget ("/buttonsmc")
gotoAndPlay (option);

Obviously this code won't work, but I'd be interested in knowing if this is possible. What I'm interested in doing is using the same flash file (it contains navigation buttons) in different web pages (to save load time). When the user opens a web page, I want various movie clips to be set to different frame labels depending on which site you open. Each web page would have an associated status.txt file with different variable settings. For instance, on one web page, I might want the /buttonsmc clip to be open, and within that, another clip to show a highlighted state. In another web page, i might want the /buttonsmc clip to be closed, and another movie clip to be open.
Thanks again for your help.
-King Dufus
 
Don't understand why my "Flash 5" code wouldn't work with you? I imported the Flash 4 .fla into Flash 5... It was automatically adapted to Flash 5 syntax, and that's what I posted. Just checked it again... And it still works!

As for eliminating the conditional statement, I don't understand that either! Thought that was the whole idea!

On top of which, I don't understand why you're looking for Flash 4 player compatibility in the first place, since by now, and especially with the Flash 6 player (beta) already out, most user's players must have been upgrated.

And this Flash 5 syntax would work without the conditional statement:

on (press) {
_root.buttonsmc.gotoAndStop (option);
}

The only problem with this, is that this will only work if a label has been set, corresponding to whatever option's value is set to, in the text file.
In other words, if an "open" or "close" label has been set and option equals either, then the goto will work. Otherwise, the button will just seem inactive, because it's got no defined "where" to go to!

Regards,
And might I be blessed with your vote!




new.gif
 
Hi OldNewbie,
Thanks for the follow-up. The latest code worked great. However, it looks as if there is a problem with the loadVariablesNum ("status.txt", 0); function. The code only worked if I allowed at least three frames in between the Load function and the _root.buttonsmc.gotoAndStop (option); function. It seems as if Flash needs time to load the variables into the movie before it can use them. I'm not sure how to make sure the entire text file has been loaded before continuing with the rest of the code, aside from inserting frames. The problem is that what may work on my machine, may not on a slower one. Do you have any ideas?
Thanks again!
-King Dufus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top