开发者

As3 buttons become disabled

开发者 https://www.devze.com 2023-02-11 05:01 出处:网络
Alright, I broke down my example to avoid complicating things. I have 2 buttons on the first frame, housed by a movieclip called \'container\'. The MOUSE_OVER/OUT is for animations which are inside t

Alright, I broke down my example to avoid complicating things.

I have 2 buttons on the first frame, housed by a movieclip called 'container'. The MOUSE_OVER/OUT is for animations which are inside the buttons movie clip, and stop with stop(); (inside the movieclip button).

stop();


container.addEventListener(MouseEvent.CLICK, clickCommand);

function clickCommand(event:MouseEvent):void{
    if(event.target.name == "button1"){
        container.alpha = 0;
        gotoAndStop(15);
    }
        if(event.target.name == "button2"){
        container.alpha = 0;
        gotoAndStop(16);
    }
}


container.addEventListener(MouseEvent.MOUSE_OVER, rollOverCommand);

function rollOverCommand(event:MouseEvent):void{
    if(event.target.name == "button1"){
        event.target.gotoAndPlay(2);

}
    if(event.target.name == "button2"){
        event.target.gotoAndPlay(2);
    }

}



container.addEventListener(MouseEvent.MOUSE_OUT, rollOutCommand);

function rollOutCommand(event:MouseEvent):void{
    if(event.target.name == "button1"){
        event.target.gotoAndPlay(11);
    }
    if(event.target.name == "button2"){
        event.target.gotoAndPlay(11);
    }
}

As you can see, I want the container to alpha to 0 when the user clicks eigher button, then have the timeline hop to the corresponding frame, depending if the user picked button 1(frame15) or button 2(frame 16).

This works 开发者_如何学Gojust fine. The problem is I have a new menu on these frames which is also housed in a movie clip called container2 - and their MOUSEOVER/OUT/CLICKs suddenly dont work when I use this approach. Here is their code:

stop();

    container2.addEventListener(MouseEvent.CLICK, clickCommand2);

function clickCommand2(event:MouseEvent):void
{
    if (event.target.parent.name == "main1")
    {
        event.target.root.gotoAndPlay(13);
        trace(event.target.parent.name);
    }
    else if (event.target.parent.name == "main2")
    {
        trace(event.target.parent.name);
        event.target.root.gotoAndStop(14);
    }
}


container2.addEventListener(MouseEvent.MOUSE_OVER, rollOverCommand2);

function rollOverCommand2(event:MouseEvent):void
{
    if (event.target.name == "main1","main2")
    {
        event.target.parent.gotoAndPlay(16);

    }
}



container2.addEventListener(MouseEvent.MOUSE_OUT, rollOutCommand2);

function rollOutCommand2(event:MouseEvent):void
{
    if (event.target.name == "main1","main2")
    {

        event.target.parent.gotoAndPlay(21);

    }
} 

So I can get to the frame I want, but the new buttons (main1,main2) I have placed their are disabled.

Is it because I didn't remove the listeners? Am I going about this the wrong way?

Thanks in advance - it's much appreciated.


I'm going to assume your code has been added to the actions, rather than added to a separate AS file.

A few suggestions. If your buttons span the entire timeline, and don't move, make sure they're on their own layer, with no new keyframes, that way the same instance is preserved and the event listeners should work just fine.

If your buttons are different instances, you'll need to rebind the event listeners on the keyframe that you jump to.

Whenever possible, avoid using actions for managing your actionscript code. putting your code in an external AS file can significantly reduce code duplication.

0

精彩评论

暂无评论...
验证码 换一张
取 消