Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌套的电影剪辑时间线在Flash AS2中不起作用(深度/目标)_Flash_Nested_Actionscript 2_Targets - Fatal编程技术网

嵌套的电影剪辑时间线在Flash AS2中不起作用(深度/目标)

嵌套的电影剪辑时间线在Flash AS2中不起作用(深度/目标),flash,nested,actionscript-2,targets,Flash,Nested,Actionscript 2,Targets,当所有mc都放在主时间线(舞台)上时,我的代码工作正常,但是当我将它们导入名为Container\u mc的单个电影剪辑时,代码停止工作。我确信这与目标/深度有关 下面是在时间线上工作的代码 stop (); first = 1; import mx.transitions.Tween; import mx.transitions.easing.*; function dragSetup(clip, targ) { clip.onPress = functi

当所有mc都放在主时间线(舞台)上时,我的代码工作正常,但是当我将它们导入名为Container\u mc的单个电影剪辑时,代码停止工作。我确信这与目标/深度有关

下面是在时间线上工作的代码

 stop ();


    first = 1;



    import mx.transitions.Tween;
    import mx.transitions.easing.*;

function dragSetup(clip, targ) {
clip.onPress = function() {
startDrag(this);

};

clip.onRelease = clip.onReleaseOutside=function () {
stopDrag();

if (eval(this._droptarget) == targ) {
var tx:Tween=new Tween(this,'_x',Elastic.easeOut,this._x,this.myFinalX,1,true);
var ty:Tween=new Tween(this,'_y',Elastic.easeOut,this._y,this.myFinalY,1,true);
targ.gotoAndStop(2);
} else {
var tx:Tween=new Tween(this,'_x',Elastic.easeOut,this._x,this.myHomeX,1,true);
var ty:Tween=new Tween(this,'_y',Elastic.easeOut,this._y,this.myHomeY,1,true);
targ.gotoAndStop(2);
}
};
//the variables below will store the clips starting position
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;
//the variables below will store the clips end position
clip.myFinalX = targ._x;
clip.myFinalY = targ._y;

}

dragSetup(drag1,target1)
dragSetup(drag2,target2)
dragSetup(drag3,target3)



btn.onRelease = function() {




  if ((_root.drag1._droptarget == "/target1") && (_root.drag2._droptarget == "/target2") && (_root.drag3._droptarget == "/target3")) {


                    if (first == 1) {
            first = 0;
            result += 
                }

          comment = "Great! correct answer";
         _root.attachMovie("glamour", "glamour2", 202);
             _root.glamour2._x = 226;
              _root.glamour2._y = 153;



    } else {
        comment = "try again!!";

        first = 0;
    }

}
我很确定问题出在BTN函数中的IF station中,因为当导入到容器中时,上面的其余代码工作正常,这只是IF语句,而else“重试”答案刚刚返回,即使目标是正确的


有人有什么想法吗?

在按钮处理程序中,您对
\u root
有几处引用。这可能是问题的原因,因为我认为drag1、drag2等都在您的容器中。此函数中的代码在您的按钮范围内执行,因此,如果按钮与drop movieclips位于同一时间线上,则您可以安全地将所有出现的
\u root
替换为
\u parent

不过,更好的方法是将按钮处理程序的范围更改为容器的范围,这意味着您不需要根或父。这是通过委托完成的:

btn.onRelease = Delegate.create(this,buttonHandler);

function buttonHandler() { 
    if ((eval(drag1._droptarget) == target1) && (eval(drag2._droptarget) == target2) && (eval(drag3._droptarget) == target3)) { 
        // only if all three dragable objects are dropped to their respective targets sentence returns true  
        if (first == 1) { first = 0; result += } 
        comment = "Great! correct answer"; 
        attachMovie("glamour", "glamour2", 202); 
        glamour2._x = 226; 
        glamour2._y = 153;
} else {
    comment = "try again!!";
    first = 0;
}
请确保导入脚本顶部的委托类,以使其正常工作:

import mx.utils.Delegate;

第二种方法更好,因为您不必担心不同的范围,而且它与AS3中使用的方法类似。

0 down vote accept感谢您的快速回复!!更新后的代码如下,但我仍然得到“重试返回”不是正确答案?你知道为什么吗?我已经做了很多年了:)我更新了我的答案,我遗漏了一个重要的部分。在if中,您正在比较放置目标的值,我将其更改为
eval()
the _droptarget,并将结果与一个对象进行比较。这里有一个完整的解释:,但基本上,_droptarget返回一个斜杠符号字符串,因此“/target1”与用点符号表示的_root.target1相同。Eval转换为点表示法,因此您可以与舞台上的实际对象进行比较。