So basically the only way to make this work is to declare the myMovieClip as
a global variable??

-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Gerry
Sent: Thursday, April 21, 2011 9:28 PM
To: Flash Coders List
Subject: Re: [Flashcoders] How to access MovieClip declared in one function
in an event listener

Steve,

You have some things confused. Like Ross said, read up on event.target.

Your code should look something like this...

Var myMovieClip:MovieClip;
Var myButton:SimpleButton;

DrawMyStuffOnScreen();


Function DrawMyStuffOnScreen():void{

               myMovieClip = new DefinedMovieClip();

               myButton = new DefinedButton();

               myButton.addEventListener(MouseEvent.CLICK,DoSomething);

               //Defined Movie clip has several input fields in it

               myMovieClip.TextField.text = "SomeText";

               addChild(myMovieClip);
                addChild(myButton);
}

Function DoSomething(e:MouseEvent):void{
                        
               //What goes in this function to be able to do something like

               Trace(myMovieClip.TextField.text); // This show a complier
error of basically I don't know what myMovieClip is;
}


On Apr 21, 2011, at 9:44 PM, Steve Abaffy wrote:

> Hello,
> 
> 
> 
> I basically have the follow:
> 
> 
> 
> Function DrawMyStuffOnScreen():void{
> 
>                Var myMovieClip:MovieClip = new DefinedMovieClip();
> 
>                Var myButton:SimpleButton = new DefinedButton();
> 
>                myButton.addEventListener(MouseEvent.CLICK,DoSomething);
> 
> //Defined Movie clip has several input fields in it
> 
>                myMovieClip.TextField.text = "SomeText";
> 
>                addChild(myMovieClip);
> 
> }
> 
> Function DoSomething(MouseEvent.CLICK):void{
> 
>                What goes in this function to be able to do something like
> 
>                Trace(myMovieClip.TextField.text); // This show a complier
> error of basically I don't know what myMovieClip is;
> 
> 
> 
>                Then tried:
> 
>                Var myMC = new DefinedMovieClip();
> 
>                Trace(myMC.TextField.text) // this works but is always
empty
> since it initializes empty. 
> 
>                So how do you access the textfield that is sitting on the
> stage???
> 
> }
> 
> Thanks
> 
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to