0

I have a flex application only used as API of LocalConnection for JavaScript. It's working well but the generated SWF file is really big:

  • static-link-runtime-shared-libraries=false ~43k
  • static-link-runtime-shared-libraries=true ~260k

Both are really big and if static-link-runtime-shared-libraries is disabled - loading the swf is nearly 5 seconds slower and rendomly I get Error #2046 :(

Compressing and optimizing is enabled, debugging and the preloader is is disabled.

The mxml file only contains the following:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="main()"
    width="1" height="1" usePreloader="false">
<mx:Script>
    <![CDATA[
        import mx.core.FlexGlobals;
        import flash.net.LocalConnection;
        import flash.external.ExternalInterface;

        private var readyCallback:String;
        private var debugCallback:String;
        private var errorCallback:String;

        private var receiveConnection:LocalConnection;
        private var receiveCallback:String;

        private var postConnection:LocalConnection;

        private function main() : void {
            // ...
        }

        // ~100 Lines of code
    ]]>
</mx:Script>
</mx:Application>

Can someone help me generating a much smaller (and fast loading) swf ?

mabe.berlin
  • 1,043
  • 7
  • 22
  • 1
    43k for a Flex application is actually quite small. It's a bulky framework. You can create a SWF as small as 4k without Flex (create an Actionscript project in Flash Builder). This app will extend the `Sprite` class instead of Flex's bulky `Application` class, which it sounds like you don't really need :) – Sunil D. Nov 14 '12 at 19:28
  • Does that mean I have to use the ``compc`` compiler ? - but how to generate swf files from it – mabe.berlin Nov 14 '12 at 21:50
  • @mabe you can use mxmlc, but flex classes will not be included in swf – Timofei Davydik Nov 14 '12 at 22:22
  • @Timofei Davydik How can I exclude the flex classes from swf? – mabe.berlin Nov 14 '12 at 22:25
  • 1
    You can [use mxmlc](http://stackoverflow.com/questions/4169729/compile-actionscript-using-mxmlc-compiler) to compile the Actionscript project. – Sunil D. Nov 14 '12 at 22:30
  • Don't know about it compiling *.as classes directly using mxmlc - thank you, will try it tomorrow on work. – mabe.berlin Nov 14 '12 at 22:41
  • @mabe Just don't use them :) – Timofei Davydik Nov 15 '12 at 09:00

1 Answers1

0

The main issue was to write an *.mxml application instead of a simple basic *.as class extending Sprite which can be compiled with mxmlc, too.

Now the file looks like this:

package {
    import flash.display.Sprite;
    import flash.external.ExternalInterface;
    import flash.net.LocalConnection;
    import flash.events.StatusEvent;

    public class MyClass extends Sprite
    {
        // ...
    }
}

Now the file is ~1.2k and loads very quick :)

Much thanks @Timofei Davydik and @Sunil D.

mabe.berlin
  • 1,043
  • 7
  • 22