当所有mc都放在主时间线上(舞台)时,我的代码工作得很好,但是当我将它们导入到一个名为Container_Mc的电影剪辑中时,代码停止工作。我确定这和target/depth
有关下面是时间线
上的代码 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;
}
}
我很确定问题在于IF语句中的BTN函数,因为上面的其余代码在Container_Mc内导入时工作良好,它只是IF语句,否则"再试一次"答案只是返回,即使目标是正确的?
有人有什么想法吗?
在您的按钮处理程序中,您有几个对_root
的引用。这可能是问题的原因,因为我想象的drag1, drag2等都在您的容器内。此函数中的代码在按钮范围内执行,因此,如果按钮与放置影片剪辑在同一时间轴上,那么您可以安全地将_root
替换为_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中使用的方法相似。