R – Flex application to component

actionscript-3apache-flexcomponentsflexbuildermxml

I have an application built in Flex Builder 3. It has a fair amount of mxml and as3 code which uses some other custom compenents. I have looked at the documentation on building components which shows how to make a simple mxml or action script component that extends something like a combobox, but I'm lost as to how to take a whole existing and independently functioning Application and turn it into a reusable component.

Basically, I'd just like to create multiple instances of this app inside of another flex project.

Anyone able to provide a little guidance?

Best Answer

The easy thing to do is to swap the Application mxml tag with a VBox tag...thus making it act like a component.

e.g. If this were your application:


//Foo.mxml
<mx:Appliction xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Label text = "foo" />
</mx:Appliction>

change it to:


//Foo.mxml
<mx:VBox>
    <mx:Label text = "foo" />
</mx:VBox>

and then you can do something like this:


//App.mxml
<mx:Appliction 
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:local="your.package.scheme.*"
>
    <local:Foo />

</mx:Appliction>

You may have to make some public properties if you need to pass in any data to the component...

Related Topic