RE: [flexcoders] as3 global variables - no more
Global is bad and went directly against OOP. To do it right, you want your component to broadcast an event, and the other componet to listen for that event and then call another method when the event is heard. Jason Merrill Bank of America GT&O L&LD Solutions Design & Development eTools & Multimedia Bank of America Flash Platform Developer Community Are you a Bank of America associate interested in innovative learning ideas and technologies? Check out our internal GT&O Innovative Learning Blog <http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/default.aspx> and & subscribe <http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/_layouts/SubNew.a spx?List=%7B41BD3FC9%2DBB07%2D4763%2DB3AB%2DA6C7C99C5B8D%7D&Source=http% 3A%2F%2Fsharepoint%2Ebankofamerica%2Ecom%2Fsites%2Fddc%2Frd%2Fblog%2FLis ts%2FPosts%2FArchive%2Easpx> . From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of dsds99 Sent: Friday, February 22, 2008 1:42 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] as3 global variables - no more Yes, using global variables was easy solution to referencing movieclips from anywhere. I'm trying to link up my play button to play the selected track in a listbox. The two components are in separate classes. one solution is that in my main class I pass a reference of the listbox to my playbutton. Are there alternative solutions to this...Better OOP practice.
RE: [flexcoders] as3 global variables - no more
Events are the preferred solution, but from anywhere in an app, including swfs loaded using SWFLoader, you can access any public member in the main application scope doing: Import mx.core.Application; Then: var myVar:String = Application.application.publicStringVarInMainApp; //works for public functions and components too. I typically create a var, _app:Application, to shorten the code. If you type _app to the exact class (file name) of the main app, you will get the benefits of code hinting in FB. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Paul Andrews Sent: Friday, February 22, 2008 1:50 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] as3 global variables - no more - Original Message - From: "dsds99" <[EMAIL PROTECTED] <mailto:dsds99%40yahoo.com> > To: mailto:flexcoders%40yahoogroups.com> > Sent: Friday, February 22, 2008 6:41 PM Subject: [flexcoders] as3 global variables - no more > Yes, using global variables was easy solution to referencing > movieclips from anywhere. > > I'm trying to link up my play button to play the selected track in a > listbox. The two components are in separate classes. > > one solution is that in my main class I pass a reference of the > listbox to my playbutton. > > Are there alternative solutions to this...Better OOP practice. I thin k you either have a class missing, or the wrong push button class. The button gets pressed and should fire off an event. In your application there needs to be a class that responds to the pushbutton. That class is also aware of the list, so it can know the button is pressed then access the current item on the list and activate the playing. A method of this application class can be called by the buttons click handler.. Paul
Re: [flexcoders] as3 global variables - no more
One way is to use singleton classes. # package pkg { # # public class SingletonClass { # # public var someVar:String = 'Hello World'; # # //singleton instance makes sure there is only one instance of the class # static private var myInstance:SingletonClass; # # public function SingletonClass( singletonEnforcer:SingletonEnforcer ){} # # //returns an instance to the node and enforces singleton class # public static function getInstance( ): SingletonClass { # # if( SingletonClass .myInstance == null ) # SingletonClass.myInstance = new SingletonClass( new SingletonEnforcer() ); # # return SingletonClass.myInstance; # } # # } # } # # # //publicly inacsessable dummy class used to enforce signleton # class SingletonEnforcer { } Your class instance could then be accessed anywhere in the application with: # import pkg.SingletonClass; # # trace( SingletonClass.getInstance().someVar ); Regards, ~Aaron On 2/22/08, dsds99 <[EMAIL PROTECTED]> wrote: > > > > > > > Yes, using global variables was easy solution to referencing > movieclips from anywhere. > > I'm trying to link up my play button to play the selected track in a > listbox. The two components are in separate classes. > > one solution is that in my main class I pass a reference of the > listbox to my playbutton. > > Are there alternative solutions to this...Better OOP practice. > > -- Aaron Miller Chief Technology Officer Splash Labs, LLC. [EMAIL PROTECTED] | 360-255-1145 http://www.splashlabs.com
Re: [flexcoders] as3 global variables - no more
- Original Message - From: "dsds99" <[EMAIL PROTECTED]> To: Sent: Friday, February 22, 2008 6:41 PM Subject: [flexcoders] as3 global variables - no more > Yes, using global variables was easy solution to referencing > movieclips from anywhere. > > I'm trying to link up my play button to play the selected track in a > listbox. The two components are in separate classes. > > one solution is that in my main class I pass a reference of the > listbox to my playbutton. > > Are there alternative solutions to this...Better OOP practice. I thin k you either have a class missing, or the wrong push button class. The button gets pressed and should fire off an event. In your application there needs to be a class that responds to the pushbutton. That class is also aware of the list, so it can know the button is pressed then access the current item on the list and activate the playing. A method of this application class can be called by the buttons click handler.. Paul
[flexcoders] as3 global variables - no more
Yes, using global variables was easy solution to referencing movieclips from anywhere. I'm trying to link up my play button to play the selected track in a listbox. The two components are in separate classes. one solution is that in my main class I pass a reference of the listbox to my playbutton. Are there alternative solutions to this...Better OOP practice.