Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-20-2007, 11:46 PM   #1
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default Help making a solution

Where to begin....

I have to create these "InfoModules" that are manufactured by an .swf file. The modules textual appearance changes by an xml. Which InfoModule loads at run time I don't know as that is also determined by the xml file and a factory. The same InfoModule has be able to have additional "decorations" to it (see first image attached and both are a representation of InfoModule1) depending on which .swf manufactures it. In the module on the left, there is 1 additional visual element added, that is a line. In the module on the right, there are 3 additional visual elements added: 2 lines and a grey box. However, there may be no visual elements added as this is to be determined by the .swf that makes the InfoModules. For instance, if InfoModule2 is instantiated, no decorations are needed.

Here is how the modules are being manufactured:
ActionScript Code:
private function onXML(event:Event):void {    _xml = XML(event.currentTarget.data);                _module = infoModuleFactory(_xml.@module);    addChild(_module); }         private function infoModuleFactory(def:String):InfoModule {    // dynamically get class instance from xml doc    var ModuleReference:Class = getDefinitionByName(def) as Class;    return new ModuleReference(_xml); }
a diagram of the Modules is also attached.

I just don't know how to add these visual elements. I was thinking of getting rid of the getDefinitionByName way of doing this, and making each "template" .swf file have its own factory and when InfoModule1 is created in the factory, adding those visual elements. If InfoModule2 is create, no visual elements...etc. The problem with this is when I add a new InfoModuleNth, I will have to go back through all the "template" factories and include this new InfoModule. Maybe that just comes with the territory....

Attached Thumbnails
Click image for larger version

Name:	ModuleTemplates.jpg
Views:	148
Size:	105.2 KB
ID:	23767   Click image for larger version

Name:	InfoModule Layout.jpg
Views:	146
Size:	88.4 KB
ID:	23768  
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman

Last edited by Flash Gordon; 08-21-2007 at 12:16 AM..
Flash Gordon is offline   Reply With Quote
Old 08-21-2007, 12:57 AM   #2
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

Here is code of what I was thinking. Please let me know how this looks to you. I need it to stay flexible and easily maintainable. I don't want to program this thing and then 6 months down the road realize I did a horrible job. I need your experience!

DocumentClass
ActionScript Code:
package {     public class DocumentClass extends Sprite     {         private var _factory:InfoModuleFactory = new InfoModuleFactory();                         public function DocumentClass()         {             //         }                 private function onXML(event:Event):void         {             _xml = XML(event.currentTarget.data)                            _infoModule = _factory.create(InfoModuleFactory.INFO_MODULE1);             _infoModule.consume(_xml);             _infoModule.build();             _infoModule.x = 20;             _infoModule.y = 30;             addChild(_infoModule);                         // can only decorate after module is built because decorations are based upon the inner works of the modules             var decorate:DecorateModule = new DecorateModule(_infoModule);             decorate.build(InfoModuleFactory.INFO_MODULE1);         }     } }

InfoModuleFactory: this class creates the actual modules
ActionScript Code:
package {     public class InfoModuleFactory     {                 public static const INFO_MODULE1:String = "infoModule1";         public static const INFO_MODULE2:String = "infoModule2";                         public function InfoModuleFactory()         {             //         }                 public function create(type:String):InfoModule         {             var infoModule:InfoModule;             switch(type)             {                 case INFO_MODULE1:                     infoModule = new InfoModule1();                     break;                 case INFO_MODULE2:                     infoModule = new InfoModule2();                     break;             }                         return infoModule;         }     } }
DecorateModule: adds specific graphics to each module including the scrollbar graphics. Each main .swf file will have it's own DecorateModule class.
ActionScript Code:
package template1 {     public class DecorateModule     {                 protected var _module:InfoModule;         public function DecorateModule(module:InfoModule)         {             _module = module;         }                 public function build(type:String):void         {             switch(type)             {                 case "infoModule1":                     addLine();                     break;                 case "infoModule2":                     // nothing                     break;             }         }                 private function addLine():void         {             var line:MovieClip = new LineGraphic()// gets line from library             var mask:DisplayObject = _module.getChildByName("mask");             line.x = mask.x;             line.y = mask.y + mask.height + 20;             _module.addChild(line);         }     } }

Cheers if you got this far
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman

Last edited by Flash Gordon; 08-21-2007 at 08:55 AM..
Flash Gordon is offline   Reply With Quote
Old 08-22-2007, 07:12 PM   #3
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

Anybody?

If need be, I'll play you for your input.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 08-25-2007, 05:41 AM   #4
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 838
Default

Well, if there's no way around the use of a unique concrete class for each module, but you want to make it extensible, why not have each concrete class be represented as an external swf, then you can have your factory load the external swf that matches the name of the module in the xml. Then have each swf's document class abstracted to the same base class, and you can handle each one the same way.

Quote:
Originally Posted by Flash Gordon View Post
Anybody?

If need be, I'll play you for your input.
You'll play me?? I've been had! =o
Assertnfailure is offline   Reply With Quote
Old 08-25-2007, 07:43 AM   #5
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

Quote:
Originally Posted by Assertnfailure View Post
...then you can have your factory load the external swf that matches the name of the module in the xml. Then have each swf's document class abstracted to the same base class, and you can handle each one the same way.
Much thanks for the reply! If I understand you correctly, that is about how I have it now, except for that I'm not loading .swf's but just instantiating classes. What is the benefit of making them actual .swf as apposed to just classes?

Quote:
Originally Posted by Assertnfailure View Post
You'll play me?? I've been had! =o
HA! Chump, you've been punk'd. LoL....DOH.... .... quite the typo.

Thanks again for the response!
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 08-25-2007, 07:55 AM   #6
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 838
Default

Well external swfs are the only way to inject classes into a precompiled application. There are two benefits with this.

1) You can add more swfs instead of recompiling the same swf over and over...which is nicer for distribution.

2) You cut down on the filesize of the primary swf, because the code is dispersed across multiple files, and not all files need to be loaded if they aren't all used.
Assertnfailure is offline   Reply With Quote
Old 08-25-2007, 08:51 PM   #7
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

That's true about the loading .swf's at runtime and that's a good point. However, in my case I would also need to recompile a separate DecorateModule for each template and load that as well as DecorateModule is unique to each template. You gave me something to definitely think about!

The strange thing about OOP is it doesn't always lend to the smoothest user experience. It can slow down game play and if I'm loading 15 different modules it can increase initial loading times (having to wait for loads rather than just instantiating classes). However, it does always make maintenance easier, so in the end it is a decision of which is the more important for this situation.

Thanks a lot for all the great responses, Assertnfailure. I really appreciate the help you have given me!
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 08-26-2007, 08:28 PM   #8
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 838
Default

Yeah....OOP is really more of a utilization of faster computers to focus on development efficiency rather than process efficiency. After all, even simple things like breaking code into functions uses additional resources.

Haha, no problem dude. Conventions and architecture are much more interesting topics than "how to attach a movieclip," and it seems you're the only one utilizing this section so far.
Assertnfailure is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
making a window close after specified amount of time bullettobinary ActionScript 2.0 1 06-11-2005 11:17 AM
Making draggable movie clips undraggable? tryin_to_learn ActionScript 2.0 10 05-20-2005 02:15 AM
Making a MC stay at current positon after scene change Xclint ActionScript 1.0 (and below) 4 05-04-2005 11:30 PM
need help making component Billy T ActionScript 1.0 (and below) 13 09-24-2002 02:13 PM
making my clock into analogue?? Crapatscript Simple Stuff (Newbies) 2 03-20-2002 05:50 PM


All times are GMT. The time now is 07:40 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.