actionscript 3 - Type Coercion Failed in Action Script 3, getting element from an array -


i'm getting error when i'm getting element array , trying use functions on it:

typeerror: error #1034: type coercion failed: cannot convert jogador$ jogador. @ laser/mover_tiro_baixo()

sorry it's in portuguese, code i'll paste below, think it: when retrieve element array it's of type 'jogador$', , if try use being of 'jogador' doesn't work. i'm trying manually force coercion, trying convert object displayobject (because i'm trying use hit test function), didn't work:

typeerror: error #1034: type coercion failed: cannot convert jogador$ flash.display.displayobject. @ laser/mover_tiro_baixo()

code:

package {      import flash.display.movieclip;     import flash.display.stage;     import flash.events.event;     import flash.debugger.enterdebugger;     import flash.utils.getdefinitionbyname;     import flash.utils.getqualifiedclassname;     import flash.display.displayobject;       public class laser extends movieclip {          private var velo: number;         private var meupalco: stage;         var dono: movieclip;         var inimigotipo: number;         var inimigos: array;         var dano: number;         var tam:number;         var i:number;          public function laser(palco: stage, posx: number, posy: number, velocidade: number, dano: number, cimabaixo: number, dono: movieclip, vetjogadores: array) {             this.dono = dono;             this.dano = dano;             if (getclass(this.dono) == "jogador") {                 inimigotipo = 0;                 inimigos = jogador(this.dono).vetorinimigos;             } else {                 inimigotipo = 1;                 inimigos = vetjogadores;             }             this.meupalco = palco;             this.velo = velocidade;             this.x = posx;             this.y = posy;             if (cimabaixo == 1) {                 this.addeventlistener(event.enter_frame, mover_tiro_cima);             } else {                 this.addeventlistener(event.enter_frame, mover_tiro_baixo);             }             meupalco.addchild(this);         }           public function mover_tiro_cima(evt: event) {             this.y -= velo;             if (inimigotipo == 0) { // dono tiro é o player                           var tam: number = inimigos.length;                 var i: number = 0;                 while (i < tam) {                     if (this.hittestobject(inimigos[i])) {                             inimigo(inimigos[i]).vida.diminuir(this.dano);                         }                         i++;                     }                 } else { // dono tiro é um inimigo                     tam = inimigos.length;                     = 0;                     while (i < tam) {                         if (this.hittestobject(inimigos[i])) {                                 jogador(inimigos[i]).vida.diminuir(this.dano);                             }                             i++;                         }                     }                     if (this.y <= 0) {                         this.removeeventlistener(event.enter_frame, mover_tiro_cima);                         meupalco.removechild(this);                     }                 }                  public function mover_tiro_baixo(evt: event) {                     this.y += velo;                     if (inimigotipo == 0) { // dono tiro é o player                                    tam = inimigos.length;                          = 0;                         while (i < tam) {                             if (this.hittestobject(inimigos[i])) {                                     inimigo(inimigos[i]).vida.diminuir(this.dano);                                 }                                 i++;                             }                         } else { // dono tiro é um inimigo                             tam = inimigos.length;                             = 0;                             while (i < tam) {                                 if (this.hittestobject(inimigos[i])) {                                         jogador(inimigos[i]).vida.diminuir(this.dano);                                     }                                     i++;                                 }                             }                             if (this.y <= 0) {                                 this.removeeventlistener(event.enter_frame, mover_tiro_baixo);                                 meupalco.removechild(this);                             }                         }                          static function getclass(obj: object): string {                             return  string(class(getdefinitionbyname(getqualifiedclassname(obj))));                         }                     }                  } 

the error happens everytime laser tests see if it's hitting enemy (hittest) in functions. mover_tiro_baixo() moves shot down.

thanks people!

edit: way create arrays:

var player1:jogador = new jogador(stage,350,700,10,3,1); var jogadores:array = [jogador]; player1.setjogadores(jogadores);  var inimigo1:et = new et(stage,100,200,jogadores); var inimigo2:et = new et(stage,200,100,jogadores); var inimigo3:et = new et(stage,350,450,jogadores);  var todosinimigos:array = [inimigo1,inimigo2,inimigo3]; player1.definirinimigos(todosinimigos); 

i've checked other stack overflow questions have similar type conversion errors. of other people similar problem filling array class, rather objects instances of class. filling arrays this?

for(var i:int = 0; < 10; i++){      inimigos.push(jogador); //incorrect } 

if so, reason problem happening. correct way it:

for(var i:int = 0; < 10; i++){      inimigos.push(new jogador()); //correct } 

edit:

in new code added first post, line seems problem:

var jogadores:array = [jogador]; //jogador class 

flash actionscript arrays cannot "initialized" able contain specific type of object. actionscript vectors capable of that, not arrays. line posted above initializes array in first element class, not object.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -