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
RE: [Flashcoders] How to access MovieClip declared in one function in an event listener
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;
Re: [Flashcoders] How to access MovieClip declared in one function in an event listener
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 placesright? * 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 functionTHEN 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.)
RE: [Flashcoders] How to access MovieClip declared in one function in an event listener
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. And you still shouldn't have to. I haven't followed this thread, and don't have time at the moment to dig in, but there still should be no need for a global variable in your application, if that makes you feel any better. Jason Merrill Instructional Technology Architect Bank of America Global Learning -- This message w/attachments (message) is intended solely for the use of the intended recipient(s) and may contain information that is privileged, confidential or proprietary. If you are not an intended recipient, please notify the sender, and then please delete and destroy all copies and attachments, and be advised that any review or dissemination of, or the taking of any action in reliance on, the information contained in or attached to this message is prohibited. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept, monitor, review and retain e-communications (EC) traveling through its networks/systems and may produce any such EC to regulators, law enforcement, in litigation and as required by law. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or free of errors or viruses. References to Sender are references to any subsidiary of Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the foregoing. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] How to access MovieClip declared in one function in an event listener
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
Re: [Flashcoders] How to access MovieClip declared in one function in an event listener
read up on event.target. 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
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
RE: [Flashcoders] How to access MovieClip declared in one function in an event listener
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
Re: [Flashcoders] How to access MovieClip declared in one function in an event listener
Steve, You can also track by using event.currentTarget, like this: function DoSomething(e:MouseEvent):void{ trace((event.currentTarget).TextField.text); } -- Greetings! Hope this message of mine finds you in best of health and spirits. On Fri, Apr 22, 2011 at 10:05 AM, Steve Abaffy st...@msmarketing.bizwrote: 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