0
votes

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.

2
You didn't forget to put the stop(); in your frame2, right? - danii
That not needed. As i do: GotoAndStop(2) for going to frame 2. - user838097

2 Answers

1
votes

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)
}
0
votes

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