Steve,

I suggest you read up on eventListeners in Actionscript 3.

I provided an example that dispatches a new event called "what text", it 
doesn't pass that as a string to another function. I did this
because you are creating your movieClip within a function so it's scope will 
only be within that function...so I added the eventListener
to that movieClip to listen for the dispatched event named "what text".

"DrawTheMainScreen - These are the items on the stage that stay all the time."
If they are on the screen at all times then you would want to declare those 
outside of that function first so that they can be referenced in 
other places....right? *

It sounds  like you want to display a bunch of objects on the stage that are 
available at all times. So with that said you'd want to 
write the vars for those objects outside of your function....THEN when you call 
DrawTheMainScreen it sets what those objects are.
Now when you click on that button your click event can fire an event that can 
reference anything that is on the stage*.

*see my first code example. 

Let me know if you're still unclear and I'll send some more code.

-Gerry

On Apr 22, 2011, at 10:24 AM, Steve Abaffy wrote:

> Well my basic understanding of programming goes something like this.
> We call functions to do certain things when we need them to do it, so:
> Basic flowchart of program.
> 
> LoadExternalData - This data will be loaded into movieclips to be place on
> the stage at a later time.
> DrawTheMainScreen - These are the items on the stage that stay all the time.
> DrawNavigationButtons - These buttons will load the different things on the
> screen that change. This is where the EventListeners for the buttons are
> defined.
>       FirstButtonClickedListener - Calls ClearscreenFunction, which clears
> the screen of all previous things on the stage that are not to stay all the
> time
>               Then Draw the stage for this Menu Item.
>       SecondButtonClickedListenr - Cals ClearscreenFunction.
>               Then Draws the stage for this MenuItem. This screen is a
> input form which has a button on it to do something with the information
> entered. Declares Listener for this button.
>               ButtonListener is called and now we can't access any of the
> information on the form.
> 
> So in my opinion it would be better if you could declare the Listener as
> follows:
>       
> myButton.addListener(Event,ParamatersToPass,FunctionsToCall); With the
> parameter list to be optional if not needed.
> 
> Then declare the Function accordingly.
> 
> The example of  trace((event.currentTarget).TextField.text);
> Here event.currentTarget is the button itself which of course does not have
> any textfields associated with it.
> 
> Another example was to write two function one that calls is the
> eventListener and then have the eventListener call another eventListener
> where you are passing "What Text" where are you getting the value of "What
> Text"? If I could get the value of "What Text" in this function I wouldn't
> need the other function so I am a bit confused as to how that will solve
> anything. The only example that seems to work is to make the movieClip a
> global variable, which seems to me to violate everything I have ever been
> taught about programming. Which is to say that one should use global
> variables as sparingly as possible. I have written thousands of lines of
> code in my 30+ years as a programmer and probably only used global variables
> once or twice before OOPs programming became the rage.
> 
> 
> -----Original Message-----
> From: flashcoders-boun...@chattyfig.figleaf.com
> [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Gerry
> Sent: Friday, April 22, 2011 6:15 AM
> To: Flash Coders List
> Subject: Re: [Flashcoders] How to access MovieClip declared in one function
> in an event listener
> 
> "There is more than one way to skin a cat" - crazy expression but you can do
> what you want a number of ways in AS3.
> I guess knowing that you only want to add that movieClip from within the
> function would change things in the sample I sent.
> 
> 
> Here's another basic version (not knowing what you are doing with the code
> or movieClips) ...
> 
> function DrawMyStuffOnScreen():void{
> 
>              var myMovieClip:MovieClip = new DefinedMovieClip();
>             myMovieClip.TextField.text = "SomeText";
>             myMovieClip.addEventListener("What text", showWhatText);
> 
>             var myButton:SimpleButton = new DefinedButton();
> 
>              myButton.addEventListener(MouseEvent.CLICK,DoSomething);
> 
>              addChild(myMovieClip);
>               addChild(myButton);
> }
> 
> function DoSomething(e:MouseEvent):void{
>                       /* This is called from the button which will
> dispatch a new event that your movie clip is listening for */
> 
>                       dispatchEvent(new Event("what text"));
> }
> 
> function showWhatText(e:Event):void{
>       /* This event fires when the event "What text" happened */
>       trace(e.target.TextField.text);
> }
> 
> 
> 
> 1.) Why are you declaring your MovieClip within the function? 
> 2.) Does that movieClip and button have to be added to the stage at a
> certain time?
> 3.) Is all of this code on the timeline?
> 
> -Gerry
> 
> 
> On Apr 22, 2011, at 12:35 AM, Steve Abaffy wrote:
> 
>> 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
>> 
> 
> 
> _______________________________________________
> 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