actionscript 3 - Error #1009 and randomInterval() in as3 -


i used given code animation templates scripted rain. code looks this:

stop();   // number of symbols add. const num_symbols:uint = 175;  var symbolsarray:array = []; var idx:uint; var drop:rain;  (idx = 0; idx < num_symbols; idx++) {     drop = new rain();     addchild(drop);     symbolsarray.push(drop);     // call randominterval() after 0 given ms.     settimeout(randominterval, int(math.random() * 10000), drop); }  function randominterval(target:rain):void {      // set current rain instance's x , y property      target.x = math.random()* 800-50;     target.y = math.random() * 50;      //randomly scale x , y     var ranscale:number = math.random() * 3;     target.scalex = ranscale;     target.scaley = ranscale;      var tween:string;     // ranscale between 0.0 , 1.0     if (ranscale < 1) {         tween = "slow";      // ranscale between 1.0 , 2.0     } else if (ranscale < 2) {         tween = "medium";      // ranscale between 2.0 , 3.0     } else {         tween = "fast";      }     //assign tween nested in myclip     myclip[tween].addtarget(target);  }  sentences_btn.addeventlistener(mouseevent.click,  fl_clicktogotoandstopatframe);  function fl_clicktogotoandstopatframe(event:mouseevent):void {     gotoandstop(5); }  button3.addeventlistener(mouseevent.click, fl_clicktogotoandstopatframe_2);  function fl_clicktogotoandstopatframe_2(event:mouseevent):void {     gotoandstop(20); } 

every time move new keyframe error , not know how correct it. can please me? thank you.

typeerror: error #1009: cannot access property or method of null object reference.     @ untitled_fla::maintimeline/randominterval()     @ function/http://adobe.com/as3/2006/builtin::apply()     @ setintervaltimer/ontimer()     @ flash.utils::timer/_timerdispatch()     @ flash.utils::timer/tick() 

most likely causes null reference line myclip[tween].addtarget(target);, @akmozo pointed in comments.

i guess, when go keyframe, myclip no longer available. so, have 2 choices: 1 -- extend myclip keyframes in question, keeps raining there, or 2 -- stop rain cancelling timeouts. latter need save timeouts ids somewhere, can cancel them later. code below illustrates idea.

// number of symbols add. const num_symbols:uint = 175;  var symbolsarray:array = []; var timeouts:array = []; // -- list of timeouts var idx:uint; var drop:rain;  (idx = 0; idx < num_symbols; idx++) {     drop = new rain();     addchild(drop);     symbolsarray.push(drop);      // call randominterval() after 0 given ms.     // -- add timeout id list     timeouts.push(         settimeout(randominterval, int(math.random() * 10000), drop)     ); }  // -- call method stop rain, when change keyframes function stoprain() : void {     (var i:int = 0; i<timeouts.length; i++) {         cleartimeout(timeouts[i]);     } } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -