PDA

View Full Version : Use module as Class Library?


kdittyr
09-10-2009, 09:05 PM
The issue that I am having right now is that I am loading up to twenty very small modules based on dynamic data. This works fine, but it is slow to load as I have to wait for one module to completely load before I initiate the next module load. Also, it is wasting a lot of bandwidth to load the same module more than once.

My client would like me to, instead, load a module and use that as a Class Library. That would allow me to load a controls module once, then use that to create as many play buttons (or any other control) as I need. I have written a class that I have used on other, non-Flex, projects where I load swf's into my application and then call my getClass method which returns the requested class. public function getClass(_e:*, _class:*):Class
{
try{
var myclass:* = _e.target.applicationDomain.getDefinition(_class) as Class;
}catch(e:Error){
return null;
}
return myclass;
}
I am trying to use this with a module, or an application file, but cannot get it to work. The reason I am going for one of those is because my controls are extensions of Flex buttons, HSliders and so forth...

As it stands now, I have them working when they are just imported into my main application, but I am trying to see get something working that will last (dynamically) further than this single compile.

Does this make sense?

I am hoping someone can help point me in the right direction.

Peter Cowling
09-10-2009, 10:29 PM
The issue that I am having right now is that I am loading up to twenty very small modules based on dynamic data.

You load modules using variable data...


This works fine, but it is slow to load as I have to wait for one module to completely load before I initiate the next module load.

You load all modules at once...during initialization...


Also, it is wasting a lot of bandwidth to load the same module more than once.

...more than once.

You can load modules when you need them. That is really the idea of them, otherwise you just add overhead (Optimized modules are more expensive than if you just incoporate the whole lot in one .swf.) And you do not want to be loading modules time and again.


The getClass stuff is not something I would use if I was using modules...

kdittyr
09-11-2009, 12:26 AM
Thanks for the reply!

I guess I still have a few questions, but I will continue to think about this so I can ask the right ones.

Is there a way to duplicate/replicate a module once it is loaded?

Thanks for streamlining my original post :)

Peter Cowling
09-11-2009, 08:36 AM
Is there a way to duplicate/replicate a module once it is loaded?


If you have common requirements, it is best to place them not in a module, but in the main application. In mvc, this would be the 'm'/model part. It is analogous to your getClass idea, but you would tend to myModel.getInstance() from your main application - rather than having the class independent from your app.

EDIT

The reason I am going for one of those is because my controls are extensions of Flex buttons, HSliders and so forth...

Overlooked that part of what we are talking about are controls and not data/statefulness. These do not go on models, but should be in the main application. You might fold them into a .swc, and add them to your library.


The issue that I am having right now is that I am loading up to twenty very small modules based on dynamic data.

And re-reading this with that in mind makes me think that what you have is 20 data related states. It is not usual for their to be a 1-1 relationship between these states and a module. I think that modules only justify their overhead when you get to 125-150k (at release build), and you can do a lot with this amount of space...