el problema es que kisiera editar una variable que tengo en una clase
accedo a esta mediante un getChildByName()
ya que la variable ke la creo se encarga de crear al resto de los npcs
el codigo es algo asi:
Código ActionScript:
es el ke se encarga de crear los npcVer original
for(var xgm:int=1; xgm <=100; xgm++){ trace('MDid_'+xgm); if(vars['MDid_'+xgm]){ if(npc['tmpIdNpc_'+xgm]){ trace("No"); _mainMap.getChildByName("npc_"+npc['tmpIdNpc_'+vars['MDid_'+xgm]]).pos_x = vars['MDcorx_'+xgm]; _mainMap.getChildByName("npc_"+npc['tmpIdNpc_'+vars['MDid_'+xgm]]).pos_y = vars['MDcorx_'+xgm]; }else{ trace("Si 2"); _idNpc++; var chuy:Npc = new Npc(vars['MDlifeb_'+xgm],vars['MDcorx_'+xgm],vars['MDcory_'+xgm],vars['MDname_'+xgm],1,1); chuy.x = vars['MDcorx_'+xgm]; chuy.y = vars['MDcory_'+xgm]; chuy.name="npc_"+_idNpc; npc['tmpIdNpc_'+vars['MDid_'+xgm]] = _idNpc; _mainMap.addChild(chuy); if(_idNpc==1){ _mainMap.addEventListener(Event.ENTER_FRAME, followInTheMap); } } }else{ xgm+=100; } }
y el archivo clase de npc es:
Código ActionScript:
Ver original
package { import flash.display.MovieClip; import flash.events.Event; import flash.text.*; public class Npc extends MovieClip { public var life:Number; public var pos_x:Number; public var pos_y:Number; public var rute:Number; public var iniRuteTime:Number; public var _name:String; public var _move:Number; private var speed:Number = (55/20); private var posRuteX:Number; private var posRuteY:Number; private var corx:Number; private var cory:Number; private var new_x:Number; private var new_y:Number; private var new_x2:Number; private var new_y2:Number; private var contenedor2:Number = 0; private var contenedor:MovieClip = new MovieClip(); private var name_txt:TextField = new TextField(); public function Npc(fLife:Number,fPosx:Number,fPosy:Number,fName:String,finiRuteTime:Number,fmove:Number) { _move = fmove; _name=fName; life = fLife; pos_x = fPosx; pos_y = fPosy; iniRuteTime = finiRuteTime; rute = 1; iniRuteTime = 0; if(fName=="55GK-Kurck"){ contenedor = new tileSet1(); }else if(fName=="39UC-Typhoon"){ contenedor = new tileSet3(); }else if(fName=="78CQ-Imperia"){ contenedor = new tileSet4(); }else if(fName=="98CR-Metamoft"){ contenedor = new tileSet6(); }else { contenedor = new tileSet100_rutenium(); } contenedor.x=-50; contenedor.y=-50; contenedor.stop(); this.addChild(contenedor); this.addEventListener(Event.ENTER_FRAME, actStatus); } private function actStatus(e:Event):void { this.x=this.pos_x; this.y=this.pos_y; if(contenedor2==0){ name_txt.type=TextFieldType.DYNAMIC; name_txt.text=_name; name_txt.width=120; name_txt.height=16; name_txt.x=-60; name_txt.y=50; name_txt.selectable = false; name_txt.textColor = 0x99FFFF; name_txt.autoSize = TextFieldAutoSize.CENTER; this.addChild(name_txt); contenedor2++; } //Validamos ruta normal if(rute == 1){ posRuteX=1000;posRuteY=1000; } if(rute == 2){ posRuteX=2500;posRuteY=5000; } if(rute == 3){ posRuteX=1700;posRuteY=200; } if(rute == 4){ posRuteX=3080;posRuteY=2300; } if(rute == 5){ posRuteX=4080;posRuteY=3500; } if(rute == 6){ posRuteX=2050;posRuteY=4000; } new_x = posRuteX-this.x; new_y = posRuteY-this.y; //Comprobamos que no se pase. var absX:Number=Number(new_x.toString().split('-').join(''));var absY:Number=Number(new_y.toString().split('-').join('')); if(absX<=speed && absY<=speed){ if(rute!=6){rute++;}else{rute=1;} }else{ if(absX<=(speed*3) && absY>speed){if(new_x>=0){new_x2 = new_x+speed; }else{ new_x2=new_x-speed;}new_y2=new_y;/*trace(new_x+","+new_y);trace(new_x2+","+new_y2);*/}else if(absY<=(speed*3) && absX>speed){if(new_y>=0){new_y2=new_y+speed; }else{new_y2=new_y-speed; }new_x2 = new_x;/*trace(new_x+","+new_y);trace(new_x2+","+new_y2);*/}else{ new_x2=new_x;new_y2=new_y; } } if(new_x2>=0){ corx=speed; }else{ corx = 0-speed; } if(new_y2>=0){ cory=speed; }else{ cory = 0-speed; } if(corx < 0 && cory < 0){ this.contenedor.gotoAndStop('4'); } if(corx >= 0 && cory < 0){ this.contenedor.gotoAndStop('3'); } if(corx >= 0 && cory >= 0){ this.contenedor.gotoAndStop('2'); } if(corx < 0 && cory >= 0){ this.contenedor.gotoAndStop('1'); } this.x = this.x+corx; this.y= this.y+cory; pos_x = this.x; pos_y = this.y; } } }
No se que estoy haciendo mal... por favor ayudenme : )
intento acceder a la variable pos_x y pos_y de esta forma
_mainMap.getChildByName("npc_"+npc['tmpIdNpc_'+vars['MDid_'+xgm]]).pos_x = vars['MDcorx_'+xgm];
_mainMap.getChildByName("npc_"+npc['tmpIdNpc_'+vars['MDid_'+xgm]]).pos_y = vars['MDcorx_'+xgm];
pero me da error