0

当所有 mc 都放在主时间线(舞台)上时,我的代码工作正常但是,当我将它们导入到名为Container_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 FUNCTION中的IF 语句中,因为上面的其余代码在Container_Mc中导入时可以正常工作,它只是 if 语句,即使目标正确,也会返回 else“再试一次”答案?

任何人有任何想法?

4

1 回答 1

0

在您的按钮处理程序中,您有几个对_root. 这可能是问题的原因,因为我想drag1、drag2 等都在您的容器内。此函数中的代码在您的按钮范围内执行,因此如果该按钮与放置影片剪辑在同一时间轴上,那么您可以安全地替换所有出现的_rootwith _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;
}

请务必在脚本顶部导入 Delegate 类以使其正常工作:

import mx.utils.Delegate;

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

于 2011-04-05T09:51:27.797 回答