当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to compile a flex file only used for LocalConnection + JS-API

问题描述:

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 ?

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: