Código:
class Pet { var Name:String; var Attacks:Array = new Array(); function Pet(){ trace("nuevo pet"); } function tracing(){ trace(this.Name); trace("-------START ATTACKS TRACE---------------"); for (var i:Number=0;i<Attacks.length;i++){ trace("-------START ATTACK "+i+"---------------"); var currentattack:Attack = new Attack(); currentattack=Attacks[i]; currentattack.tracing(); } } }
y usando este codigo:
Código:
var pet1:Pet = new Pet(); var pet2:Pet = new Pet(); var pet3:Pet = new Pet(); var pet4:Pet = new Pet(); var attack1:Attack = new Attack(); var attack2:Attack = new Attack(); var attack3:Attack = new Attack(); var attack4:Attack = new Attack(); pet1.Name="pet1"; pet2.Name="pet2"; pet3.Name="pet3"; pet4.Name="pet4"; attack1.name="attack1"; attack2.name="attack2"; attack3.name="attack3"; attack4.name="attack4"; pet1.Attacks.push(attack1); pet2.Attacks.push(attack2); pet3.Attacks.push(attack3); pet4.Attacks.push(attack4); trace("------PET 1---------------"); pet1.tracing(); trace("------PET 2---------------"); pet2.tracing(); trace("------PET 3---------------"); pet3.tracing(); trace("------PET 4--------------"); pet4.tracing(); trace("---------------------");
and the output is this:
Código:
------PET 1--------------- pet1 -------START ATTACKS TRACE--------------- -------START ATTACK 0--------------- attack1 -------START ATTACK 1--------------- attack2 -------START ATTACK 2--------------- attack3 -------START ATTACK 3--------------- attack4 ------PET 2--------------- pet2 -------START ATTACKS TRACE--------------- -------START ATTACK 0--------------- attack1 -------START ATTACK 1--------------- attack2 -------START ATTACK 2--------------- attack3 -------START ATTACK 3--------------- attack4 ------PET 3--------------- pet3 -------START ATTACKS TRACE--------------- -------START ATTACK 0--------------- attack1 -------START ATTACK 1--------------- attack2 -------START ATTACK 2--------------- attack3 -------START ATTACK 3--------------- attack4 ------PET 4-------------- pet4 -------START ATTACKS TRACE--------------- -------START ATTACK 0--------------- attack1 -------START ATTACK 1--------------- attack2 -------START ATTACK 2--------------- attack3 -------START ATTACK 3--------------- attack4 ---------------------
porque usan el mismo array de objetos todas las instancias? como se hace para tener un unico array de objetos cada clase? Gracias