flash - "this" is undefined -


i java/php developer helping actionscript. don't understand why "this" undefined in below code. snippet of code, it's gives idea of i'm trying reference "this". i'm trying find out movie tween moving can load next movie. tweens used move movies in , out of screen.

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 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! here working code after applying tips responses/answers:

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 can used in settimeout()     settimeout(function () {          var movie = tweeny.obj;//use ref movie affected 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 

if trying trace out tween_move_1, can refer directly inside settimeout().


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -