View Full Version : Compiling components independently to application

04-01-2008, 04:49 PM
The application I am working on draws custom components based on a list retrieved from a database ("DynamicElem1","DynamicElem2"). For example
for each(var elemName:String in elemList)
var classToUse:Class = getDefinitionByName(elemName) as Class;
var cfElem:UIComponent = new classToUse;

At a later date further components may be required, eg DynamicElem3. I would like to develop the application so that the components can be compiled independently of the main application but still be used by the main application as above. Is this possible? Thanks.

04-01-2008, 05:16 PM
Yes. You can compile them into a SWF, load the SWF into your application at runtime, and access those components through the loaded SWFs ApplicationDomain.

04-02-2008, 09:52 AM
I've taken a quick look at this and have a few more questions. How can I compile an ActionScript class into an SWF using Flex Builder? Am I able to use the component the same as any well known component in the main SWF? My components will implement an interface that is well known by the main application, would I need to specify the interface in a shared library so it can be used in all SWF's? Thanks.

04-07-2008, 09:41 AM
I didn't have much success using the application domain, so I've looked into a different approach which seems to work but I was wondering whether this will have any negative impact of application size/performance?

- I've created a library project (ElemInterfaces) which contains a number of interfaces implements by the elements
- I've created a number of library projects (Elem1, Elem2...). These link to the ElemInterfaces library with a link type of External.
- I've created another library project (Componentslist) which links to the other libraries. It contains a single class which declares variables of type Elem1, Elem2 etc
- I've created my main application which links to ComponentsList with the Link Type set as RSL. It also links to ElemInterfaces with the link type set to External.
- In the main application I can instantiate objects of type Elem1 and Elem2 using GetDefinitionByName as below.

I can also create a new Elem library, link this to ComponentsList, compile ComponentsList and deploy without needing to compile my main application.

Is this an acceptable design? Also, I'm having some problems using the External link type. Linking to ElemInterfaces as External is fine, but if I try to set the link in ComponentsList to Elem1 to External I get the following run time error 'VerifyError: Error #1014: Class mx.containers::VBox could not be found.' But when it is 'Merged in code' it is fine. Any ideas would be much appreciated.