RE: [Flashcoders] Class for movie - best practice question
This AS2 class acts like the document class in AS3. You need to extend MovieClip like you need to extend Sprite or MovieClip in AS3. Tracing this in the class will result in _level0, its not composition. Its really useful for swf that you load, gives you the ability to type check everything on the root timeline without having to create an empty clip on the timeline etc... And I've thrown in EventDispatcher in there which is really useful as well. BLITZ | Patrick Matte - 310-551-0200 x214 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Ngo Sent: Tuesday, April 24, 2007 9:01 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Class for movie - best practice question Why would you extend MovieClip and composition a MovieClip as well? Seems a bit redundant, no? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Matte | BLITZ Sent: Tuesday, April 24, 2007 7:09 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Class for movie - best practice question Try this class. Put new ApplicationClass(this); on the first frame of the timeline. import mx.events.EventDispatcher; class ApplicationClass extends MovieClip{ public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function ApplicationClass(target){ target.__proto__ = __proto__; this = ApplicationClass(target); EventDispatcher.initialize(this); init(); } private function init(){ trace("this = " + this); } } You can also use that class as a generic class for all your timelines and extend it like this import mx.utils.Delegate; import it.sephiroth.XML2Object; class RootClass extends ApplicationClass{ public function RootClass(target){ super(target); } private function init(){ trace("override init this = " + this); } } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Class for movie - best practice question
Why would you extend MovieClip and composition a MovieClip as well? Seems a bit redundant, no? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Matte | BLITZ Sent: Tuesday, April 24, 2007 7:09 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Class for movie - best practice question Try this class. Put new ApplicationClass(this); on the first frame of the timeline. import mx.events.EventDispatcher; class ApplicationClass extends MovieClip{ public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function ApplicationClass(target){ target.__proto__ = __proto__; this = ApplicationClass(target); EventDispatcher.initialize(this); init(); } private function init(){ trace("this = " + this); } } You can also use that class as a generic class for all your timelines and extend it like this import mx.utils.Delegate; import it.sephiroth.XML2Object; class RootClass extends ApplicationClass{ public function RootClass(target){ super(target); } private function init(){ trace("override init this = " + this); } } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Class for movie - best practice question
Try this class. Put new ApplicationClass(this); on the first frame of the timeline. import mx.events.EventDispatcher; class ApplicationClass extends MovieClip{ public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function ApplicationClass(target){ target.__proto__ = __proto__; this = ApplicationClass(target); EventDispatcher.initialize(this); init(); } private function init(){ trace("this = " + this); } } You can also use that class as a generic class for all your timelines and extend it like this import mx.utils.Delegate; import it.sephiroth.XML2Object; class RootClass extends ApplicationClass{ public function RootClass(target){ super(target); } private function init(){ trace("override init this = " + this); } } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Class for movie - best practice question
If you like Java so much, why don't you marry it? If you want to make deferential commentary regarding Actionscript, go to Java forums and seek validation from your Java friends. Unlike us Flashcoders, I'm sure they'd be happy to oblige. It's extremely easy to make a document class in AS2 and it is most certainly not a hack. You make an empty movieclip (CTRL+F8), assign your main class to it (under Linkage), put it on the root timeline at 0,0 and you're done. Doesn't get much easier than that. It's not a hack, there is nothing negative about it and it has quite a few positives. Just build your entire application within that clip. The "hacks" that I have seen about how to force the root to have a class assigned to it are complicated at best, and unnecessary (as I have just illustrated) at worst, not to mention you can run into issues when you take into account FlashVars and other _root considerations. When I'm developing, I hear two voices in my head: Judge Judy says, "KISS! Keep It Simple, Stupid." and David Hansson says "DRY! Don't Repeat Yourself." ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Class for movie - best practice question
There are a number of ways of essentially 'hacking' AS2 to behave in a more classic OO manner. Personally, as it IS a hack no matter what you do in AS2, I always keep it simple and just import a Main.as file, rather than go to unnecessarily elaborate lengths to fool myself that I'm really using a stricly typed, perfectly conventioned OO based language. But fear not, AS3 will let you create the document class you long for. In the most mature example of popular commercial OO based code, Java, the best practice is always to call the main dcument class "main". If you stick with Java best practices you won't go wrong with AS. Sean McSharry > Hi, just wanted to know if there is a best practice when creating a class > for the mother movie (i.e. the flash-movie itself). Is > this the way to go? > > var mother:MyFabFlashApp = new MyFabFlashApp(); > > ..or is there a better way? Seems kind of a stupid question, but I wanted > to put it anyway in case I've missed something. ;-) I'veput my main code > on the first frame of the _root timeline for too long, and want to move it > into a class. > > Regards, > > /Johan Nyberg > > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Class for movie - best practice question
Best practices: A lot of people use main.swf and main.as. FLASC/MTASC has a feature to support this very functionality. Never put classes in the same folder as your movie. Always put them in a namespace folder chain. For instance: class com.clientname.projectname.Main HTH, Steven Johan Nyberg wrote: Hi, just wanted to know if there is a best practice when creating a class for the mother movie (i.e. the flash-movie itself). Is this the way to go? var mother:MyFabFlashApp = new MyFabFlashApp(); ..or is there a better way? Seems kind of a stupid question, but I wanted to put it anyway in case I've missed something. ;-) I'veput my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan Nyberg ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Class for movie - best practice question
One way: In the same directory as your SWF. Have a main class with a static function that takes in a movie clip. In your FLA put code in Frame 1 like: MainClass.main(this); The "this" is the root movie clip. The static function main will pass it around to who ever needs it in your application. It depends how you want to handle it but this is a starting point. Hope this helps, Rob. Johan Nyberg wrote: Hi, just wanted to know if there is a best practice when creating a class for the mother movie (i.e. the flash-movie itself). Is this the way to go? var mother:MyFabFlashApp = new MyFabFlashApp(); ..or is there a better way? Seems kind of a stupid question, but I wanted to put it anyway in case I've missed something. ;-) I'veput my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan Nyberg ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] Class for movie - best practice question
Hi, just wanted to know if there is a best practice when creating a class for the mother movie (i.e. the flash-movie itself). Is this the way to go? var mother:MyFabFlashApp = new MyFabFlashApp(); ..or is there a better way? Seems kind of a stupid question, but I wanted to put it anyway in case I've missed something. ;-) I'veput my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan Nyberg ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com