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?

David Wolever
  • 148,955
  • 89
  • 346
  • 502

2 Answers2

2

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
  • 645
  • 3
  • 9
  • 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 Jul 23 '10 at 16:27
  • 1
    project properties > modules. Everything in there automatically gets deployed. – jeremy.mooer Jul 27 '10 at 18:46
0

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
  • 3,119
  • 1
  • 19
  • 16
  • 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 Jul 21 '10 at 17:45
  • 1
    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 Jul 22 '10 at 06:59