Here is an example that illustrate how you can upload an image or a swf in your Flash ActionScript 3.0 project .
ActionScript 3.0 code:
addChild(_mc);
var request:URLRequest = new URLRequest("image.jpg"); // Create the URLRequest with the path to the object you want to load.
var loader = new Loader(); // Create the Loader object.
loader.load(request);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
function onLoadProgress(event:ProgressEvent):void // Call this function when the object is loading.
{
trace(int(event.bytesLoaded/event.bytesTotal*100)+"%"); // Display the percentage loaded.
trace(event.bytesLoaded+":"+event.bytesTotal); // Display the bytes loaded and the total number of bytes.
}
function onLoadComplete(event:Event):void // Call this function when the object is loaded.
{
// Duplicate and resize a loaded image (doesn’t work for swf).
// —–>
var objectDuplicate:Bitmap = new Bitmap(loader.content.bitmapData.clone());
objectDuplicate.width = 100;
objectDuplicate.height = 100;
objectDuplicate.smoothing = true;
_mc.addChild(objectDuplicate);
// —–>
_mc.addChild(loader); // Attach object to MovieClip.
}
function onLoadError(event:Event):void // Call this function if the path to the object that you want to load is not valid.
{
trace("Error! The URL was not found.");
}


Leave a Comment