actionscript 3 - Accessing Movieclip added by a different function in the same class? -


i can't seem find answer problem. can't following work:

public class callbattle extends movieclip     { import flash.display.movieclip; import flash.display.stage; import flash.display.interactiveobject; import flash.events.mouseevent; import global.globalvar;      public var battlegraphics:array = new array();     public function battle()     {            var battlewindow:movieclip = new battlewindow() movieclip;         battlegraphics.push(addchild(battlewindow));         battlewindow.x = 4;          battlewindow.y = 248;          var attackbutton:movieclip = new battlebutton() movieclip;         battlegraphics.push(addchild(attackbutton));         attackbutton.x = 192;          attackbutton.y = 255;          attackbutton.addeventlistener(mouseevent.click, attackclicked);       }      public function attackclicked(event:mouseevent):void{         battlegraphics[attackbutton].y = 248;     } 

}

i'm getting error

battlegraphics[attackbutton].y = 248;

before trying method of adding movieclips array doing same result:

public class callbattle extends movieclip         {     import flash.display.movieclip;     import flash.display.stage;     import flash.display.interactiveobject;     import flash.events.mouseevent;     import global.globalvar; public function battle()         {                var battlewindow:movieclip = new battlewindow() movieclip;             this.addchild(battlewindow);             battlewindow.x = 4;              battlewindow.y = 248;              var attackbutton:movieclip = new battlebutton() movieclip;             this.addchild(attackbutton);             attackbutton.x = 192;              attackbutton.y = 255;              attackbutton.addeventlistener(mouseevent.click, attackclicked);              while (globalvar.battle == true){                  if (hero1turn == true){                  }             }         }          public function attackclicked(event:mouseevent):void{             attackbutton.y = 248;         }     } 

i want able access movieclip function.

thanks heaps guys, amazing -mark

the trick is, if referencing contents of array, use indexes of type int, or in cases of type string, while attackbutton undefined in function. solution pretty simple: declare attackbutton outside of battle() function, , remove var initiating attackbutton.

public class battle extends movieclip {     private var attackbutton:movieclip;     private var battlewindow:movieclip;     public function battle() {         attackbutton=new battlebutton();         battlewindow=new battlewindow();         ...     }     public function attackclicked(event:mouseevent):void {         attackbutton.y=248; // valid     } } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -