user838097
user838097

Reputation:

Going to next frames in Action Script 3.0

I am having a problem with AS 3.0 When you click on a door. You'll move to the next frame. In the next frame i tried the same. But its not working.

This is the code:

FRAME1;

stop();

deur1.addEventListener(MouseEvent.CLICK, frame2);
function frame2(event:MouseEvent)

    {
gotoAndStop(2)
        }// This part works. I am now in frame 2.

FRAME2:

deur2.addEventListener(MouseEvent.CLICK, frame3);
function frame3(event:MouseEvent)

    {
gotoAndStop(3)
        }

deur1=door1. deur2=door2
The doors are a Buttons. When i run this project. All i see are all my frames for each FPS.

This is the compile error i get: Compile errors

Scene 1, layer 'layer1' Frame 2, line 1: 1023 Incompatible override

Scene 1, layer 'layer1' Frame 2, Line 1: 1021 Duplicate function definition.

Scene 1, layer 'layer1' Frame 2, Line 3: 1000 Ambiguous reference to frame2

MainTimeLine, Line2: 1000 ambiguous reference to frame2.

Upvotes: 0

Views: 6659

Answers (2)

Mattias
Mattias

Reputation: 3907

Why not make more generic functions? If you have declared the functions in your first frame, then you can access them from other frames. Like this:

// Frame 1
function goPrevFrame(event : MouseEvent) : void
{
    nextFrame(); // or gotoAndStop(currentFrame +1);
}

function goNextFrame(event : MouseEvent) : void
{
    prevFrame(); // or gotoAndStop(currentFrame -1);
}

stop();
deur1.addEventListener(MouseEvent.CLICK, goNextFrame);

// Frame 2
stop();
deur2.addEventListener(MouseEvent.CLICK, goNextFrame);

// Frame 3
stop();
deur3.addEventListener(MouseEvent.CLICK, goNextFrame);

One thing to keep in mind is that you are not removing any of the event listeners, so you should use weak references.

deur3.addEventListener(MouseEvent.CLICK, goNextFrame, false, 0, true);

Clarifications regarding weak references in actionscript listeners

Upvotes: 0

danii
danii

Reputation: 5693

You get those Compile errors because of the names you are using for the functions. It seems "frame2" and "frame3" are reserved names. Try to use more descriptive names for your functions, it will help you (and others) to understand your code, and this way you are less likely to run into errors like these.

Try this (I also corrected the formatting to improve readability):

On frame 1:

stop();

deur1.addEventListener(MouseEvent.CLICK, go_to_frame2);

function go_to_frame2(event:MouseEvent):void
{
  gotoAndStop(2)
}

On frame 2:

deur2.addEventListener(MouseEvent.CLICK, go_to_frame3);

function go_to_frame3(event:MouseEvent):void
{
   gotoAndStop(3)
}

Upvotes: 1

Related Questions