ActionScript 3 (AS3) how to pick random array? -


i have problem, don't know how pick random array .

var enemies:array;  public function main() { entimer = new timer(1000); entimer.addeventlistener("timer", createenemy); entimer.start(); }  private function enemy1():void { var enemy1 = new enemy1(); enemies.push(enemy1); }  private function enemy2():void { var enemy2 = new enemy2(); enemies.push(enemy2); }  public function createenemy():void { //here problem how pick random enemy ?? var en = enemies[math.round(math.random() * 2)];  stage.addchild(en) } 

after im geting error:

implicit coercion of value of type array unrelated type flash.display:displayobject.

you've got few problems code.

for starters, you're defining 2 functions, enemy1 , enemy2 have looks 2 classes named enemy1 , enemy2. refrain calling functions , classes same name can confusing.

in addition, reason getting error:

implicit coercion of value of type array unrelated type flash.display:displayobject.

is because enemy1 or enemy2 classes not extend displayobject class , objects of type displayobject can added stage. object enemy1 , enemy2 classes inherit from?

your enemy object class should far inheritance goes ensure become displayobject type:

package {     import flash.display.movieclip;      public class enemy1 extends movieclip {          public function enemy1() {          }     } } 

or

package {     import flash.display.sprite;      public class enemy1 extends sprite {          public function enemy1() {          }     } } 

movieclip , sprite 2 examples of objects part of displayobject family of classes.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -