*WARNING* Programming-related post ahead.
I’ve decided to post this up as a personal note because I couldn’t find a site that explains exactly how to do this, so I just picked up bits and pieces from a few sites and managed to do this task. Quite simple actually (maybe that’s why not many sites talk about it :P ).
I’m no good with Flash at all but sometimes, you get clients who wants this bells and whistle. To cut a long story short, I need to have a menu which have different background colors on certain areas depending on which page you are viewing.
So, since it is a donkey’s job to create multiple flash files with same content but with only the colors are different, I needed to find how to jump to a specific “Scene” inside the flash file on different page.
This is how you quickly pass a value to a flash file. I’ve trimmed the code to show only the relevant ones.
As you can see, that is pretty straight-forward. Just add a query string to the flash filename. Remember that a querystring has the following syntax.
flashfile.swf?variable=value
Now time to grab this value inside the flash file and decide what to do with it.
When you pass a value to a flash file, the variable will be available under the root object. So we can grab the above value with the variable _root.goScene
In the first frame of your flash, we add the following code.
if (_root.goScene==1){
gotoAndPlay(”Scene 1″, 1)
} else if (_root.goScene==2){
gotoAndPlay(”Scene 2″, 1)
}
Based on the passed value, we decide which scene to show. Easy!
For the syntax gotoAndPlay, the first parameter is the scene name while the second is the frame number.
The language for Flash is Actionscript and is more or less like javascript.
Yeah - this is no eureka thing but hopefully this post can help other non-flash web programmers find a quick solution.
RSS feed for comments on this post · TrackBack URI
Leave a reply