PDA

View Full Version : AddChild with OnMouseEvent



Jefinho
June 2nd, 2009, 07:17 AM
Hi,

I want to dynamicly add 4 different Objects (Info1 - 4) to the Stage with one function. I have 4 different buttons (Logo1 - 4). When - for example - button 1 is clicked, I want to add Info1 to the stage; when button 2 is clicked, I want Info2 to replace Info1 at the same level (7). Somehow I cannot get the correct instance name to control Info1 - 4. I get a "NULL".

This is the code I use:



import Info1;
import Info2;
import Info3;
import Info4;
var _info1:Info1 = new Info1();
var _info2:Info2 = new Info2();
var _info3:Info3 = new Info3();
var _info4:Info4 = new Info4();

Logo1.addEventListener(MouseEvent.CLICK, laadInfo);
Logo2.addEventListener(MouseEvent.CLICK, laadInfo);
Logo3.addEventListener(MouseEvent.CLICK, laadInfo);
Logo4.addEventListener(MouseEvent.CLICK, laadInfo);

function laadInfo(evt:MouseEvent):void {
var Logonummer:String=evt.currentTarget.name.substring (4,5);
var inhoudStr:String = "_info"+Logonummer;
var inhoud:MovieClip = this[inhoudStr];
trace(inhoud) // returns NULL
addChildAt(inhoud, 7);
}


Can anyone help me out?
Thanks!

cbeech
June 2nd, 2009, 10:10 AM
i see that you are importing a series of classes for the instances '_info1-4' - do these classes extend MovieClip?

try a: trace(this[inhoudStr]);