我是一个java/php开发人员,用actionscript帮助别人。我不明白为什么“this”在下面的代码中是未定义的。这只是代码的一小部分,但希望它能提供一个我想要引用“this”的概念。我试图找出哪个电影的补间正在移动,以便我可以加载下一部电影。补间用于将电影移入或移出屏幕。“this”is undefined
var tween_move_1:Tween = new Tween(movie_0, "_x", Strong.easeOut, 1600, 150, 0.5, true);
tween_move_1.onMotionFinished = function() {
stop();
setTimeout(function() {
trace(this);//when trace runs it shows undefined
var tween_move_2:Tween = new Tween(movie_0, "_x", Strong.easeOut, 150, 1600, 0.5, true);
tween_move_2.onMotionFinished = function() {
var tween_move_1:Tween = new Tween(movie_1, "_x", Strong.easeOut, 1600, 150, 0.5, true);
};
}
,2000);//end of setTimeout
};//end of tween.onMotionFinished
UPDATE!下面是从反应/答案将提示后的工作代码:
var tween_move_in:Tween = new Tween(movie_0, "_x", Strong.easeOut, 1600, 150, 0.5, true);
tween_move_in.onMotionFinished = function() {
stop();
var tweeny = this;//create reference to this so it can be used in setTimeout()
setTimeout(function() {
var movie = tweeny.obj;//use ref to get the movie affected by the tween
var movieName:String = movie._name;
var splitArray = movieName.split("_");
var index = parseInt(splitArray[1]);
var tween_move_out:Tween = new Tween(_root["movie_"+index], "_x", Strong.easeOut, 150, 1600, 0.5, true);
tween_move_out.onMotionFinished = function() {
var tween_move_in2:Tween = new Tween(_root["movie_"+(index+1)], "_x", Strong.easeOut, 1600, 150, 0.5, true);
};
}
,2000);//end of setTimeout
};//end of tween.onMotionFinished
此外补间班的参考页帮助。 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/fl/transitions/Tween.html – 2010-07-23 20:10:59