If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
This example shows you how to load and external asset (file) in AS3. The files can be a swf, jpg, gif or png.
This particular example loads a jpg called loademe.jpg and attaches to the stage
Load Asset / external files example
// loadAsset.as
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
public class loadAsset extends Sprite{
private var _loadPath:String
private var _loader:Loader;
// Constructor
public function loadAsset(){
// Create the loader
_loader = new Loader();
// Add event listener that tells us when the
// asset can be safely accessed
_loader.contentLoaderInfo.addEventListener(Event.INIT, displayAsset);
// Create new URLRequest
var urlRequest = new URLRequest("loadme.jpg")
// Start the asset load
_loader.load(urlRequest);
}
// Display the asset once the load is complete
private function displayAsset(ev:Event){
// it to the DisplayObjectContainer
addChild(_loader.content);
}
}
}
To load the asset/file you need to open the flash file and place this AS in the timeline
import loadAsset; addChild(new loadAsset());Found this useful? How about buying me a coffee - simply click here.


