actionscript 3 - Cannot push past 1 element to basic AS3 Array -


i new , hoping it's should have been obvious.

when run code below, array newhole , newarray both return 1 on trace. code built newhole array, created newarray in hopes of troubleshooting. did not help. class bullethole contains no code didn't post that.

thank you.

import flash.display.*; import flash.events.*; import flash.ui.mouse;  mouse.hide();  var myreticle:movieclip; var holearray:array = new array(); var randomhole:number = randomnumber(1, 5); var newhole:bullethole = new bullethole(); var newarray:array = new array();  stage.addeventlistener(mouseevent.mouse_move, followreticle); stage.addeventlistener(mouseevent.click, myfire); stage.addeventlistener(mouseevent.click, checkcount);  function followreticle(event:mouseevent):void {     myreticle.x = mousex;     myreticle.y = mousey; }  function myfire(int):void {     stage.addchild(newhole);     newhole.x = myreticle.x;     newhole.y = myreticle.y;     //holearray.push(newhole);     newhole.gotoandstop(randomhole);     //trace(holearray.length); }  function checkcount(int):void {     newarray.push("a");     trace(newarray.length); }  function randomnumber(low:number=0, high:number=1):number {     return math.floor(math.random() * (1+high-low)) + low; } 

most issue code you've posted running on , on again. in other words, have looping timeline goes frame code you've shown on.

whenever frame reached, have following:

var holearray:array = new array(); 

which creates new array replacing used in var.

to solve this, either need to:

  • take code out of timeline (put in class file , attach document class of project)
  • re-architect timeline first frame reached 1 time
  • put checks in code runs first time frame reached.

here example of latter option:

//just define array, don't create var holearray:array;  //if array null, create (it null first time code run if(!holearray){     holearray = new array(); } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -