0
votes

I am creating a movie in flash!
In my first frame I have a triangle, second is a square, third is a rectagle and fourth is a circle.

I have created the 4 frames as stated! I want to set up an array so lets say (circle,triangle,circle,square,triangle,rectangle) I then want the movie to play like that with a second or two in between each frame?

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on/onClipEvent handler
 var active = 1;

Error Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler var timer = setInterval(gotoNext, 1000);

Error Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Statement must appear within on/onClipEvent handler function gotoNext() {

Total ActionScript Errors: 4 Reported Errors: 4

1

1 Answers

0
votes

if you compile your movie (CTRL+ENTER, CMD+ENTER) it will play your movie and will show the frames in the original order. If you can tell exactly what you are trying to do, we can help a bit more :)

Rob


Put this code on your first frame:

stop();
var active = 1;
var timer = setInterval(gotoNext, 1000);

function gotoNext() {
 active = active + 1 <= _totalframes ? active + 1 : 1;
 gotoAndStop(active);
}

This code will go through the frames (no array needed) every second one-by-one. The setInterval instance will call the gotoNext() function every second and will increment the active variable's value, then moves the playhead to the next frame. If it reaches the last frame, it goes to the first frame, creating an infinite loop.


Ok then, modify the code as below:

stop();
var frames = ['rectangle', 'circle', 'triangle', 'square'];
var active = 1;
var timer = setInterval(gotoNext, 1000);

function gotoNext() {
 active = active + 1 <= _totalframes ? active + 1 : 1;
 gotoAndStop(frames[active]);
}

This code will use the frames array and will move the playhead to the active value of the array. What you need to do is to add labels on every frame with exactly the same names as in the array.

Check out this link to see how to use frame labels: http://the-dude.co.uk/tutorials/what-are-frame-labels-and-how-do-you-use-them-flash-as2/

Good luck, Rob