AS3 movie clip button is not working

201 views Asked by At

I am creating a button out of a movie clip, and I cannot seem to figure out why it is not working. I have tried this code:(With this code over nor down will work)

import flash.events.MouseEvent;

this.buttonMode = true;

this.ContinueOver.addEventListener(MouseEvent.MOUSE_OVER, onButtonOver);
function onButtonOver( event:MouseEvent ):void
{
   gotoAndStop("over");
}

this.addEventListener(MouseEvent.MOUSE_OUT, onButtonOut);
function onButtonOut( event:MouseEvent ):void
{
   gotoAndStop("up");
}

this.ContinueDown.addEventListener(MouseEvent.MOUSE_DOWN, onButtonDown);
function onButtonDown( event:MouseEvent ):void
{
   gotoAndStop("down");
}

this.addEventListener(MouseEvent.MOUSE_UP, onButtonUp);
function onButtonUp( event:MouseEvent ):void
{
   gotoAndStop("up");
}

And I have also tried this: (with this version, the over button stays active, and the down nor up will not work)

stop();

this.CommunityCampus.communityUp1.addEventListener(MouseEvent.MOUSE_OVER, this_over);
this.CommunityCampus.communityDown1.addEventListener(MouseEvent.MOUSE_DOWN, this_down);
this.CommunityCampus.communityOver1.addEventListener(MouseEvent.MOUSE_UP, this_over);
this.CommunityCampus.communityUp1.addEventListener(MouseEvent.MOUSE_OUT, this_out);

function this_over(e:MouseEvent):void{
    this.gotoAndStop("over");
}

function this_down(e:MouseEvent):void{
    this.gotoAndStop("down");
}

function this_out(e:MouseEvent):void{
    this.gotoAndStop("up");
}
1

There are 1 answers

1
Daniel On

The code as is should work, so I can only guess the issue.

When you advance the timeline, the buttons you add actions to need to be present at all times. If the timeline advances to somewhere that the button does not exist, the action is removed, when you then go back, where the button exists, you will no longer have that action available.

You can solve this by having the buttons present at all times, and only hiding them as needed, instead of removing them.

see example image, where the button is missing for certain frames, this will cause it to not work

enter image description here