views:

93

answers:

2

I've got a module, MyModule which requires a large library:

<mx:Module>
    <mx:Script><![CDATA[
        import com.huge.library.AwesomeThing;
        var myThing:* = new AwesomeThing()
    ]]></mx:Script>
    ...
</mx:Module>

And that large library isn't referenced from my main application, except through MyModule:

<mx:Application>
    <MyModule />
</mx:Application>

But when I build with Flex Builder, com.huge.library is included in the application swf instead of the module swf, as I would expect.

So, is there any way I can trick Flex Builder into putting com.huge.library into MyModule.swf instead of MyApp.swf?

A: 

Have you got a reference to your module in the main app? Something is linking it to the main app, otherwise it wouldn't be getting included.

Check the link report from your main app to see where the dependency is being pulled in.

In FB 3 the steps are.

Open properties for the project

Flex Compiler tab

Add -link-report=true to the additional compiler arguments.

Build the application.

Check the link report.1.2.3.4.1.1.

Edit from comments.

Run the link report for your module and pare it down to purely the dependencies you want to exclude.

Now add the following line in the additional compiler arguments for your main application

-load-externs=report.xml

where report is the pared down link report.

This will prevent the dependency from being linked in your main application.

Gregor Kiddie
Yes, I do have a reference to the module in my main application (see the second code block in my question). However, I'd like to *keep* that reference, but *prevent* the large dependency from being compiled into the main application.
David Wolever
You realise it's not a module as soon as you directly reference it in code? Your whole module is included in the main app and so the act of loading it is relatively pointless...However... edited the answer for further options.
Gregor Kiddie
+1  A: 

The answer, if your example code is how you're pulling in the module, is to use a ModuleLoader and NOT have a direct reference to the module in your main application. Your app should look more like:

<mx:Application>
    <mx:ModuleLoader />
</mx:Application>

and you should load the module by doing similar to loadModule("myModule.swf"). Best of luck, Jeremy

jeremy.mooer
Darn, I thought that's what it might come to. Is there any way, then, to setup FlexBuilder so `MyModule` will be automatically compiled and exported to the "release" directory (the same way FB would do that if `MyModule` *was* directly referenced?)
David Wolever
project properties > modules. Everything in there automatically gets deployed.
jeremy.mooer