AS3按钮被禁用 [英] As3 buttons become disabled

查看:203
本文介绍了AS3按钮被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我打破了我的例子,以避免复杂的事情。

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

我有2个按钮的第一帧上,安置被称为容器的影片剪辑。该MOUSE_OVER / OUT是动画,是按钮影片剪辑,并停止与停止(); (里面的影片剪辑按钮)。

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);
    }
}

正如你所看到的,我想容器阿尔法为0,当用户点击非此即彼按钮,然后有时间轴跳跃到相应的框架,这取决于用户是否捡到1键(frame15)或按钮2(框架16)

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).

这工作得很好。问题是我对这些框架也坐落在一个影片剪辑名为container2的是一个新的菜单 - 和他们的鼠标悬停/ OUT /点击量突然不工作时,我用这个办法。这里是他们的code:

This works just 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);

    }
} 

所以,我可以得到我想要的框架,但新的按钮(MAIN1,MAIN2)我把他们都被禁止。

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?

在此先感谢 - 这是多少AP preciated

Thanks in advance - it's much appreciated.

推荐答案

我会假设你的code已被添加到动作,而不是加入到单独AS文件

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

一些建议。如果您的按钮涵盖了整个时间线,也不要动,确保他们对自己的一层,有没有新的关键帧,这样,同一个实例是preserved和事件侦听器应该工作得很好。

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.

只要有可能,尽量避免使用动作管理​​您的ActionScript code。把你的code在外部AS文件可以显著减少code复制。

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

这篇关于AS3按钮被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆