私はアクション スクリプトで誰かを支援する Java/php 開発者です。以下のコードで「this」が定義されていない理由がわかりません。これはコードのスニペットにすぎませんが、うまくいけば、「これ」を参照しようとしている場所がわかります。次のムービーをロードできるように、トゥイーンが移動しているムービーを見つけようとしています。トゥイーンは、ムービーを画面の内外に移動するために使用されます。
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
アップデート!応答/回答からのヒントを適用した後の作業コードは次のとおりです。
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