0
votes

So I've had about 3 afternoons of actionscript 3 experience, so still trying to understand all the concepts, but here's a relatively simple (I'm assuming) issue that I don't quite get.

On the stage there is a movie clip called 'num' that has three frames in it, with the numbers 1, 2 and 3 drawn on each of them. There is also a button called 'nextbtn' that goes to the next frame (on the general timeline) on click. The functions regarding 'num' are:

function num2 (): void {
   num.gotoAndStop(2);
}

function num3 (): void {
   num.gotoAndStop(3);
}

On the second frame of the timeline is the code:

stage.addEventListener(Event.ENTER_FRAME, num2);

On the third frame

stage.addEventListener(Event.ENTER_FRAME, num3);

Here is what I don't get:

These two event listeners successfully change the number on screen, but If I use the same code on the fourth frame to go back to the number 2, nothing seems to happen, the number stays at 3 even though the frames are advancing.

I know this is an incredibly newbish way of phrasing what is probably an incredibly simple concept but I am a toddler when it comes to code, so...

Any help would be greatly appreciated, thanks!

2

2 Answers

0
votes

The problem is that you don't understand those listeners, and you mess up moving on timeline as well as moving the frames of the num MovieClip. Here's what's happening:

You are on the first frame. You press some button (nextbtn) and the main timeline goes to frame 2. There is this code:

stage.addEventListener(Event.ENTER_FRAME, num2);

What it actually does is that on each tick (enter frame) it executes the num2 function:

function num2 (): void {
    num.gotoAndStop(2);
}

So if your .swf is made to run at 30 frames per second, this means that 30 times in a second the num.gotoAndStop(2) is executed. Which is meaning less - it's already on frame 2 and it's stopped. There's no idea of keep forcing it to go there and stop.

Then you press next again. It goes to frame 3. There is the same thing, but with num3. Basically it's the very same concept - force the num clip to gotoAndStop(3) thirty times a second.

What you have to do is just to call num.gotoAndStop once. Instead of adding listener for ENTER_FRAME, just call num.gotoAndStop(2) (or 3 respectively), and it will happen.

Another good idea is to either move the main timeline or the num MovieClip. Moving both is a bit weird.. It works, but as you can see, it makes you make mistakes. Hope that helps :)

0
votes

sounds to me like you don't need any ENTER_FRAME whenever you wanna go to some frame just try this code:

num.gotoAndStop(2);

if you wanna have this code after you clicked your button try this on:

back_button.addEventListener(MouseEvent.CLICK, back_clk);
function back_clk(e:MouseEvent):void
{
    prevFrame();
    // for next frame try this ===> nextFrame();
}