Actionscript 3 AS3 movieclip按钮在movieclip按钮内

Actionscript 3 AS3 movieclip按钮在movieclip按钮内,actionscript-3,flash,button,adobe,movieclip,Actionscript 3,Flash,Button,Adobe,Movieclip,我有一个与鼠标动作相关的电影剪辑。单击电影剪辑时,图像会展开以显示一些文本和另一个图像。我需要能够点击那个新的图像并检查它,但我不能点击它,因为我已经将初始电影剪辑编码为鼠标点击打开和关闭。我怎么能忽略最初的鼠标点击?我一直在寻找答案,并想出了一些我没能去工作的鼠标孩子,还把按钮放在了另一层上,但我似乎不能把我的头围绕着它 以下是初始电影剪辑的代码: step0btn.stop(); step0btn.addEventListener(MouseEvent.MOUSE_DOWN, onStep

我有一个与鼠标动作相关的电影剪辑。单击电影剪辑时,图像会展开以显示一些文本和另一个图像。我需要能够点击那个新的图像并检查它,但我不能点击它,因为我已经将初始电影剪辑编码为鼠标点击打开和关闭。我怎么能忽略最初的鼠标点击?我一直在寻找答案,并想出了一些我没能去工作的鼠标孩子,还把按钮放在了另一层上,但我似乎不能把我的头围绕着它

以下是初始电影剪辑的代码:

step0btn.stop();

step0btn.addEventListener(MouseEvent.MOUSE_DOWN, onStep0Press);
step0btn.addEventListener(MouseEvent.MOUSE_OVER, onStep0Over);
step0btn.addEventListener(MouseEvent.MOUSE_OUT, onStep0Out);

function onStep0Press(event:MouseEvent):void
{
    // toggle between frame 1 and 3 on button press
    step0btn.gotoAndStop(step0btn.currentFrame == 3 ? 1 : 3);
}

function onStep0Over(event:MouseEvent):void
{

    if (step0btn.currentFrame != 3)

    {

    step0btn.gotoAndStop(2);

}

}

function onStep0Out(event:MouseEvent):void
{
    // only switch back to UP state if the button is "pressed"
    if (step0btn.currentFrame != 3)
    {
    step0btn.gotoAndStop(1);
    }
} 
然后在里面我有另一个电影剪辑,代码如下:

step0img.stop();

step0img.addEventListener(MouseEvent.MOUSE_DOWN, onStep0imgPress);

function onStep0imgPress(event:MouseEvent):void
{
    step0img.gotoAndStop(1);

}
这一部分完全被忽略了,因为在最初的movieclip上进行了编码。我怎样才能改变这个


更新

好的,下面是新代码:

Step0img.stop();

Step0img.addEventListener(MouseEvent.MOUSE_DOWN, onStep0imgPress);

function onStep0imgPress(event:MouseEvent):void
{
    if(event.target == this.Step0btn.Step0img){
        //the click was actually the image
        this.Step0btn.Step0img.gotoAndStop(1);
    }else{
       // toggle between frame 1 and 3 on button press
       this.Step0btn.gotoAndStop(this.Step0btn.currentFrame == 2 ? 1 : 2);
    }
}
它不会给我任何错误,当我调试和电影播放良好,除了当我点击我刚刚编码的按钮。它不起作用,我得到以下错误:

TypeError: Error #1010: A term is undefined and has no properties.
    at SMARTTTraining_fla::step0_btn_7/onStep0imgPress()[SMARTTTraining_fla.step0_btn_7::frame3:7]

这里有两种方法可以实现你想要的

  • 只需在父对象上使用一键式侦听器,并检查事件的目标(与侦听器所连接的对象
    currentTarget
    相反,
    target
    是单击的最远的显示对象)

    此方法需要注意的一点是,如果
    step0img
    有子项,则它们可能是事件的目标。您可能需要执行类似于
    step0img.mouseChildren=false的操作,以防止他们成为目标

  • 以更高的优先级收听图像,然后取消事件,这样它就不会冒泡到父级

    step0img.addEventListener(MouseEvent.MOUSE_DOWN, onStep0imgPress, false, 999); //the 999 is an arbitrary number, listeners with a higher priority will be handled first, if they have the same priority (default is 0), then they will be handled backwards from order the listeners were added.
    
    function onStep0imgPress(event:MouseEvent):void
    {
        step0img.gotoAndStop(1);
        event.stopImmediatePropagation(); //this will stop the event from triggering any other listeners for it.
    }
    

  • 我一直收到“访问未定义属性step0btn”错误,我不理解。它已经定义好了,我已经编写了代码。我之前遇到过这个错误,只有当我试图在step0btn中为movieclip编写代码时才会发生。那么step0btn.step0img有什么问题?这就像当我在step0img中时,它不再识别step0btn,即使它住在那里。我想在step0btn之后添加(父级)或(根级)可能会起作用,但没有。所以,请确认-
    step0img
    step0btn
    的时间线上?另外,
    step0img
    step0btn
    的时间线的每一帧上?可能是在抛出错误时,无论step0Btn处于打开状态,都不存在
    step0img
    。我可以使用“this.step0Btn”来获取它。虽然整个过程还不起作用,但我必须再做一些调整。如果我不能让它工作,我会回复,看看你是否能进一步帮助。太好了!我的两个例子有没有帮助你解决你的问题?如果是,请接受答案,如果不是,请用您当前的绊脚石更新您的问题。如果你发现问题的解决方案完全不同,请将其作为答案发布。你能解释一下步骤按钮的层次结构吗?从您的错误和代码来看,它看起来是这样的:
    maintaline->step0\u btn\u 7->Step0btn->Step0img
    正确吗?您确定所有实例名称拼写正确吗?您的更新代码和原始发布代码之间存在差异,区分大小写。
    step0img.addEventListener(MouseEvent.MOUSE_DOWN, onStep0imgPress, false, 999); //the 999 is an arbitrary number, listeners with a higher priority will be handled first, if they have the same priority (default is 0), then they will be handled backwards from order the listeners were added.
    
    function onStep0imgPress(event:MouseEvent):void
    {
        step0img.gotoAndStop(1);
        event.stopImmediatePropagation(); //this will stop the event from triggering any other listeners for it.
    }