Random Frame [in flash]
Cats: Adobe Flash|I recently was given a project, where I was required to develop an advertisement with 10 news paper article and 10 speeches by 10 employees in it. I am being honest here I am not big on AS [Action Script], but I though that should be easy to do.
I started to work on the base [eg: bg, colours, images etc]. Now the way I laid out the movie was like this:
1. Some starting statement
2. Then 10 different scene with their article and speech.
The second step was wrong, why? Because After I did the layout while I was searching for the AS on internet there was a lot of thread advising DO NOT USE SCENE FOR THESE TYPE OF AD. Yet I ignored the fact scene being randomized is harder and requires more advanced coding. I didn’t have enough time so I decided to search Random Scene Code. Then I found my answer from David Stiller’s blog. It was a very simple code and that did my job very easily.
function getRandomLabel():String {
var labels:Array = new Array(”a”, “b”, “c”);
var index:Number = Math.floor(Math.random() * labels.length);
return labels[index];
}
this.gotoAndStop(getRandomLabel());
Please visit this link to know a lot about how it works, but I’ll just continue writing how I implemented this AS to my AD.
As I was saying my movie was laid out in deferent scene I did a simple shortcut copied all the frames from Scene 2 onward to my Scene 1 and deleted the rest of the scene.
In nutshell my movie starts and when it goes to frame 30 [for example] the AS is telling it to go to a, b, or c frame [make sure you replace a, b, c with frame numbers] that’s it. This script should work with any number of frames as far as I am concern; my movie was 5000 frame long. Enjoy….



