Max
Max

Reputation: 8045

how to load swf immediately from local data

i want to save the swf data in local so i can recreate it again and again.though most web browser has cache mechanism ,once a resource is downloaded,the application can get the resource from the local. but the browser still need to check the remote server's file's time stamp to make sure the remote file was not updated.that's make the process delay.

i want to handle it by myself ,so i save the downloaded data in the application.the trouble is i didn't find a way to recreate a new instance of the loaded swf immediately.for example,if i download a jpeg file,i finally got a bitmapdata , so i keep the bitmapdata,if i need a copy,i simply use clone() . but swf is different,i dont know how to clone the swf instance.

my way is load swf as binary array,and load it by Loader.loadBytes,here's my code.

    public static function loadSWFByte(data:ByteArray,callback:Function,domain:ApplicationDomain):void{
        var loader:Loader = new Loader();
        var f:Function = function(e:Event):void{
            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,f);
            if(callback!=null){
                callback(loader.content,loader.contentLoaderInfo);
            }
        }
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,f);
        loader.loadBytes(data,new LoaderContext(false,domain));
    }

if i need to create it,i always use callback,thus make coding complicated.Is there a way i can get the instance without using callback?

Upvotes: 0

Views: 271

Answers (1)

turbosqel
turbosqel

Reputation: 1542

Loading SWF bytes or from URL is always async , but You can load it once and clone each time:

// when loader load is complete
var cl:Class = loader.content["constructor"];
var clone:* = new cl();

Upvotes: 1

Related Questions