I am in the process of creating a new – “lite” – version of a Flex application I created a while ago. I have been porting over many of the Classes and Components to a Flex Library Project that compiles an SWC file. Because both are Cairngorm applications, I’m not able to completely eradicate duplicate code, but it seems logical that I should be able to share assets – such as icons (PNG files). What is the best way to do this? I have tried including them in the SWC, but I can’t figure out how to access them in the application. If you can help me figure that out, then my question will be answered. Any thoughts?
Here is and example of how I currently embed icons/images in my Flex application:
<mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/icons/cancelIcon.png")]
private var cancelIcon:Class;
[Bindable]
[Embed(source="assets/icons/saveIcon.png")]
private var saveIcon:Class;
]]>
</mx:Script>
Thanks.
0) First, looking at the code above – I recommend some minor changes:
—- Now, compile your library.
—- If the assets aren’t in the right place the compiler will complain
1) In your application, you need to reference the library project / swc
—- You should be able to get code hints / intellisense in Flex Builder / eclipse from classes in your Application to classes in the library project
2) In your Application – Do some code like this:
3) This will get you going – using a Library project to hold images, etc…
*** DO NOTE: If the images need to be loaded multiple times, reused, etc — There are other steps to take to squeeze out the best performance, etc…