Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex/Flash Builder : Proper way to reference another project?

Tags:

I have a fairly large Flex/Flash Builder project using Flash Builder 4.5. I want to create another project that uses some of the components from that original project. In the new project, I link resources with the original project and it works fine but the new project's file size is pretty large. It's close to the original project's file size even though it only uses a fraction of the components and assets. Is there a better way to do this to minimize the file size of the new project?

like image 203
Steven Avatar asked May 28 '12 23:05

Steven


1 Answers

You should separate all the common, reusable code into one or more library projects. In FlashBuilder you cannot convert the nature of a project from application to library, so you'll have to create a blank library project and copy over the code that you want available in both projects.

In its simplest form you project structure should look like this:

Flex app project A (swf) \
                           Flex library project (swc)
Flex app project B (swf) /

Now to use that library, go to 'Properties > Flex Build Path', click the 'Add Project...' button and select the library project you just created.

add library project

Now that you've linked to that project, you want to choose how the referenced components will be linked. (Double click on 'link type' to edit.)

choose link type

With your way of linking your projects FB apparently just compiled all classes from project A into project B. That's obviously not what you want. These are your linkage options (for an application project):

  • merged into code: only the code that is actually referenced will be compiled into the main application. So if ClassA from the lib project is never referenced and ClassB is, only ClassB will be compiled into the main application.
  • RSL: nothing is compiled into the main application, but the library is loaded at runtime; completely, since we don't know which classes we are going to need. This library is cached on the client though, so you'll have the longer load time just once. The main application will be smaller than with 'merged' linkage.

Which option to choose depends on the situation and is entirely up to you. I suggest you play around to see the difference for yourself (use a real server, because on a local server you won't get a feel for the loading times).

I should also mention there is the external linkage option, which doesn't compile any classes into the main app and also doesn't load them at runtime. This is primarily used for dependencies between libraries that will be used as RSL's in the same main application.

like image 125
RIAstar Avatar answered Sep 21 '22 15:09

RIAstar