Sunday, April 13, 2008

Loading AS1 / AS2 Flash Movies Dynamically with AS3

So, I could not find any good code snippets for loading a older AS2 Flash Movie via AS3, but several people talked about it being possible.

Also I have been using BulkLoader for loading assets into Flash and there is not a code snippet on that site (that I could find) to load a older movie from a url - there was a method that indicated it could be done. BulkLoader is a great bulk load library (open-source): http://code.google.com/p/bulk-loader/

So I finally got the right mix down and figured I would throw the class wrapper that does it out to the wild and maybe save someone a few minutes. Leave me a comment if you found the snippet useful!

package com.netrecon.test
{
import flash.display.*;
import flash.text.*;
import flash.net.URLRequest;
import flash.events.*;
import br.com.stimuli.loading.*; //BulkLoader


public class OldMovie extends Sprite
{

var loader : BulkLoader = new BulkLoader("test");
var movie:AVM1Movie = null;
var url:String =
"http://yourURL.com/YourOldMovie.swf";

public function OldMovie():void
{
// loader loads AVM1 movie
loader.add(url);


loader.addEventListener(BulkLoader.PROGRESS, onProgress);
loader.addEventListener(BulkLoader.COMPLETE, onComplete);
loader.start();
}

// bulk loader events
function onProgress(evt : BulkProgressEvent) : void{
trace(evt.percentLoaded);
}


function onComplete(evt : Event) : void
{
var movie = loader.getAVM1Movie(url);
addChild(movie);
trace("loaded old movie swf from server.");
}
//end bulk loader events
}
}


-Rask
Austin, TX - Flash Game Development
http://www.net-recon.com

3 comments:

formypast said...

hi thanks for posting this will b very beneficial for the flash peoples.






broadcast satellite services

kuldeep said...

Thanks for the post

flourence said...

Woww..i really learned from your blog...
website design perth