【发布时间】:2014-07-29 21:38:27
【问题描述】:
我有一个与鼠标操作相关的影片剪辑。当您单击影片剪辑时,图像会展开以显示一些文本和另一个图像。我需要能够单击该新图像并将其展开,但我无法单击它,因为我已经编写了初始影片剪辑以通过鼠标单击打开和关闭。我怎样才能忽略最初的鼠标点击?我一直在寻找答案,并想出了我无法开始工作的 mousechildren,并将按钮放在另一层,但我似乎无法理解它。
这是初始影片剪辑的代码:
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);
}
由于初始影片剪辑上的编码,这部分被完全忽略。我怎样才能改变这个?
更新
好的,下面是新代码:
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]
【问题讨论】:
-
您能解释一下您的步进按钮的层次结构吗?从您的错误和代码来看,它看起来像这样:
MainTimeline -> step0_btn_7 -> Step0btn -> Step0img对吗?你确定你所有的实例名称拼写正确吗?您更新后的代码与原始发布的代码之间存在区分大小写的差异。
标签: actionscript-3 flash button adobe movieclip