[Flashcoders] Basic class for swf-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've put my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan -- Johan Nyberg Web Guide Partner Sergels Torg 12, 8 tr 111 57 Stockholm 070 - 407 83 00 ___ 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] Basic class for swf-question
The way I do it is to have a static main method in your mother class that takes the root movie clip as an argument, and then in the first frame of the movie do: main.class.package.MyFabFlashApp.main(this); Most of the time that function is just something like this: public static function main(rootMC:MovieClip):Void { if(rootMC == undefined) { rootMC = _root; } // Set stage options here Stage.showMenu = false; Stage.scaleMode = noScale; Stage.align = LT; var myClass:MyClass = new MyClass(rootMC); } -Andy On 4/23/07, Johan Nyberg [EMAIL PROTECTED] 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've put my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan -- Johan Nyberg Web Guide Partner Sergels Torg 12, 8 tr 111 57 Stockholm 070 - 407 83 00 ___ 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] Basic class for swf-question
In FCS 3 you'll be able to specify a class for the _root of an swf. In Flash 8 and previous Flash versions there's no such option. One way to deal with this is the MTASC-way (code taken from http://www.mtasc.org/#usage) class Tuto { static var app : Tuto; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 _root.createTextField(tf,0,0,0,800,600); // write some text into it _root.tf.text = Hello world !; } // entry point static function main(mc) { app = new Tuto(); } } When compiling with MTASC you can then specify the name of your main class (Tuto.as) and which method to call on the class -- in this case main() mtasc -swf tuto.swf -main -header 800:600:20 Tuto.as So what it does when you compile is invoke: Tuto.main(); The code looks a bit odd though, since main() seems to accept an argument (mc) but it doesn't seem to get used and the constructor simply uses _root as the target (which IMO isn't a good idea). Without MTASC you could do the following: class Tuto { static var app : Tuto; private static var target:MovieClip; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 target.createTextField(tf,0,0,0,800,600); // write some text into it target.tf.text = Hello world !; } // entry point static function main(mc:MovieClip) { target = mc; app = new Tuto(); } } And in the main timeline you'd call: Tuto.main(this); On top of that, when not using MTASC, you can simply dump the static method entry point and use the new keyword class App{ private var target:MovieClip; function App(mc:MovieClip) { target = mc; target.createTextField(tf,0,0,0,800,600); target.tf.text = Hello world !; } } And in the main timeline: var app:App = new App(this); Ofcourse, to actually create a whole application, you'd do something else in the class constructor instead of simply creating a TextField. Then there's the ARP way of doing things - which is what I use ;-) http://osflash.org/arp/ Instead of using the main timeline as the root of your application, you create a movieclip with a class assigned to it and place it on stage. This MovieClip+Class is usually called Application. The rest of the flash app goes inside the Application MovieClip. By placing the Application movieclip on stage, you don't have to call anything from the main timeline to start the app. This is very similar to creating a Flash Form Application fla by the way, except that you're not forced to use the v2 Framework (mx.screens.Form). But the overall idea is the same: you create a tree-structure with the Application Class/MovieClip as the main timeline and the Application takes care of which child movieclip is shown/hidden. regards, Muzak - Original Message - From: Johan Nyberg [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Monday, April 23, 2007 2:09 PM Subject: [Flashcoders] Basic class for swf-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've put my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan -- 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
Re: [Flashcoders] Basic class for swf-question
hi this works for specifying a class to be associated with root: [code] import memorphic.as2.ummyProject.Application this.__proto__ = Application.prototype Application.apply(this,null) [/code] old hack, still a hack but works johan On 4/23/07, Muzak [EMAIL PROTECTED] wrote: In FCS 3 you'll be able to specify a class for the _root of an swf. In Flash 8 and previous Flash versions there's no such option. One way to deal with this is the MTASC-way (code taken from http://www.mtasc.org/#usage) class Tuto { static var app : Tuto; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 _root.createTextField(tf,0,0,0,800,600); // write some text into it _root.tf.text = Hello world !; } // entry point static function main(mc) { app = new Tuto(); } } When compiling with MTASC you can then specify the name of your main class (Tuto.as) and which method to call on the class -- in this case main() mtasc -swf tuto.swf -main -header 800:600:20 Tuto.as So what it does when you compile is invoke: Tuto.main(); The code looks a bit odd though, since main() seems to accept an argument (mc) but it doesn't seem to get used and the constructor simply uses _root as the target (which IMO isn't a good idea). Without MTASC you could do the following: class Tuto { static var app : Tuto; private static var target:MovieClip; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 target.createTextField(tf,0,0,0,800,600); // write some text into it target.tf.text = Hello world !; } // entry point static function main(mc:MovieClip) { target = mc; app = new Tuto(); } } And in the main timeline you'd call: Tuto.main(this); On top of that, when not using MTASC, you can simply dump the static method entry point and use the new keyword class App{ private var target:MovieClip; function App(mc:MovieClip) { target = mc; target.createTextField(tf,0,0,0,800,600); target.tf.text = Hello world !; } } And in the main timeline: var app:App = new App(this); Ofcourse, to actually create a whole application, you'd do something else in the class constructor instead of simply creating a TextField. Then there's the ARP way of doing things - which is what I use ;-) http://osflash.org/arp/ Instead of using the main timeline as the root of your application, you create a movieclip with a class assigned to it and place it on stage. This MovieClip+Class is usually called Application. The rest of the flash app goes inside the Application MovieClip. By placing the Application movieclip on stage, you don't have to call anything from the main timeline to start the app. This is very similar to creating a Flash Form Application fla by the way, except that you're not forced to use the v2 Framework (mx.screens.Form). But the overall idea is the same: you create a tree-structure with the Application Class/MovieClip as the main timeline and the Application takes care of which child movieclip is shown/hidden. regards, Muzak - Original Message - From: Johan Nyberg [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Monday, April 23, 2007 2:09 PM Subject: [Flashcoders] Basic class for swf-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've put my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan -- 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 -- j:pn http://www.lennel.org ___ 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] Basic class for swf-question
Yeah, I left that out on purpose ;-) - Original Message - From: Johannes Nel [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Monday, April 23, 2007 3:34 PM Subject: Re: [Flashcoders] Basic class for swf-question hi this works for specifying a class to be associated with root: [code] import memorphic.as2.ummyProject.Application this.__proto__ = Application.prototype Application.apply(this,null) [/code] old hack, still a hack but works johan ___ 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] Basic class for swf-question
Muzak, I have used Cairngorm for Flex 2 applications and I see that ARP is very very similar to it, but before I get myself and my other developer involved with ARP (on a non-forms based app), is there anything tricky I need to know about developing ARP apps without Forms, since their documentation focuses on Form development? Any help or links are greatly appreciated! Cheers! On 4/23/07, Muzak [EMAIL PROTECTED] wrote: In FCS 3 you'll be able to specify a class for the _root of an swf. In Flash 8 and previous Flash versions there's no such option. One way to deal with this is the MTASC-way (code taken from http://www.mtasc.org/#usage) class Tuto { static var app : Tuto; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 _root.createTextField(tf,0,0,0,800,600); // write some text into it _root.tf.text = Hello world !; } // entry point static function main(mc) { app = new Tuto(); } } When compiling with MTASC you can then specify the name of your main class (Tuto.as) and which method to call on the class -- in this case main() mtasc -swf tuto.swf -main -header 800:600:20 Tuto.as So what it does when you compile is invoke: Tuto.main(); The code looks a bit odd though, since main() seems to accept an argument (mc) but it doesn't seem to get used and the constructor simply uses _root as the target (which IMO isn't a good idea). Without MTASC you could do the following: class Tuto { static var app : Tuto; private static var target:MovieClip; function Tuto() { // creates a 'tf' TextField size 800x600 at pos 0,0 target.createTextField(tf,0,0,0,800,600); // write some text into it target.tf.text = Hello world !; } // entry point static function main(mc:MovieClip) { target = mc; app = new Tuto(); } } And in the main timeline you'd call: Tuto.main(this); On top of that, when not using MTASC, you can simply dump the static method entry point and use the new keyword class App{ private var target:MovieClip; function App(mc:MovieClip) { target = mc; target.createTextField(tf,0,0,0,800,600); target.tf.text = Hello world !; } } And in the main timeline: var app:App = new App(this); Ofcourse, to actually create a whole application, you'd do something else in the class constructor instead of simply creating a TextField. Then there's the ARP way of doing things - which is what I use ;-) http://osflash.org/arp/ Instead of using the main timeline as the root of your application, you create a movieclip with a class assigned to it and place it on stage. This MovieClip+Class is usually called Application. The rest of the flash app goes inside the Application MovieClip. By placing the Application movieclip on stage, you don't have to call anything from the main timeline to start the app. This is very similar to creating a Flash Form Application fla by the way, except that you're not forced to use the v2 Framework (mx.screens.Form). But the overall idea is the same: you create a tree-structure with the Application Class/MovieClip as the main timeline and the Application takes care of which child movieclip is shown/hidden. regards, Muzak - Original Message - From: Johan Nyberg [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Monday, April 23, 2007 2:09 PM Subject: [Flashcoders] Basic class for swf-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've put my main code on the first frame of the _root timeline for too long, and want to move it into a class. Regards, /Johan -- 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 -- Jordan Snyder Applications Developer Image Action LLC http://www.imageaction.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] Basic class for swf-question
Cairngorm and ARP are very similar because they used to be one and the same (or something like that - don't know the details) If you install the old ARP installer http://osflash.org/downloads/arp/ARP_2.02_Setup.exe it comes with a Sample app (PizzaService) which is a good start. Apparently it's also available on subversion: http://svn1.cvsdude.com/osflash/arp/trunk/samples/PizzaService/ There's a few extensions to ARP, more on them here: http://osflash.org/projects/arp/arp_extensions And you can find the sources here: http://svn1.cvsdude.com/osflash/arp/labs/ Other links: http://osflash.org/projects/arp One of the things that has been discussed on the ARP mailing list quite alot is the way that ARP issues commands and the fact that a Command is loosely coupled to a View. Taking the PizzaService as an example, there's an OrderForm and an OrderPizzaCommand. The OrderForm dispatches an event (orderPizza) which (through the Controller) executes the OrderPizzaCommand. The OrderPizzaCommand has a reference (viewRef) to the OrderForm and calls a method (getOrders()) on the OrderForm. So that's where it gets a bit hairy.. a Command calling a method on a View to retrieve the necessary data. Solutions are to either pass the required data to the command or go through a Model (Singleton). The OrderForm stores the required data in the Model and the OrderPizzaCommand retrieves it there. As for designing an ARP application, I found it helps to have each Form have a background movieclip, the same size as the stage, which is then hidden in the onLoad method. This helps when you need to layout and position child elements through actionscript as well (top left = 0,0) You can always join the ARP mailing list if you have more questions: http://ariaware.com/mailman/listinfo/arp_ariaware.com regards, Muzak - Original Message - From: Jordan Snyder [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Monday, April 23, 2007 11:06 PM Subject: Re: [Flashcoders] Basic class for swf-question Muzak, I have used Cairngorm for Flex 2 applications and I see that ARP is very very similar to it, but before I get myself and my other developer involved with ARP (on a non-forms based app), is there anything tricky I need to know about developing ARP apps without Forms, since their documentation focuses on Form development? Any help or links are greatly appreciated! Cheers! ___ 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] Basic class for swf-question
Thank you very much Muzak; very helpful...especially the bit about positioning movieclips. We have a very data-rich project that still needs to have plenty of Flashy goodness, and I'm more familiar with simple forms with maybe only a transition here and there. And I will be joining that list! Cheers! On 4/23/07, Muzak [EMAIL PROTECTED] wrote: Cairngorm and ARP are very similar because they used to be one and the same (or something like that - don't know the details) If you install the old ARP installer http://osflash.org/downloads/arp/ARP_2.02_Setup.exe it comes with a Sample app (PizzaService) which is a good start. Apparently it's also available on subversion: http://svn1.cvsdude.com/osflash/arp/trunk/samples/PizzaService/ There's a few extensions to ARP, more on them here: http://osflash.org/projects/arp/arp_extensions And you can find the sources here: http://svn1.cvsdude.com/osflash/arp/labs/ Other links: http://osflash.org/projects/arp One of the things that has been discussed on the ARP mailing list quite alot is the way that ARP issues commands and the fact that a Command is loosely coupled to a View. Taking the PizzaService as an example, there's an OrderForm and an OrderPizzaCommand. The OrderForm dispatches an event (orderPizza) which (through the Controller) executes the OrderPizzaCommand. The OrderPizzaCommand has a reference (viewRef) to the OrderForm and calls a method (getOrders()) on the OrderForm. So that's where it gets a bit hairy.. a Command calling a method on a View to retrieve the necessary data. Solutions are to either pass the required data to the command or go through a Model (Singleton). The OrderForm stores the required data in the Model and the OrderPizzaCommand retrieves it there. As for designing an ARP application, I found it helps to have each Form have a background movieclip, the same size as the stage, which is then hidden in the onLoad method. This helps when you need to layout and position child elements through actionscript as well (top left = 0,0) You can always join the ARP mailing list if you have more questions: http://ariaware.com/mailman/listinfo/arp_ariaware.com regards, Muzak - Original Message - From: Jordan Snyder [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Monday, April 23, 2007 11:06 PM Subject: Re: [Flashcoders] Basic class for swf-question Muzak, I have used Cairngorm for Flex 2 applications and I see that ARP is very very similar to it, but before I get myself and my other developer involved with ARP (on a non-forms based app), is there anything tricky I need to know about developing ARP apps without Forms, since their documentation focuses on Form development? Any help or links are greatly appreciated! Cheers! ___ 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 -- Jordan Snyder Applications Developer Image Action LLC http://www.imageaction.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