I wanted to design a [relatively] all purpose class to load images and SWF's with a preloader MC and error handler.
I made this BUT, when I load the MC I cannot control it.
i.e. I load an SWF containing an animated GIF, but I cannot say mc.gotoAndStop();
Example:
PHP Code:
package
{
public class test extends MovieClip
{
private var imgLoader:imageLoader;
public function test()
{
//to load the image into an MC
imgLoader = new imageLoader(imgPath,"Image name for Pre-Loader",myTarget,myWidth,myHeight,myX,myY);
}}}
Usually for myTarget I use 'this'
This is the class
PHP Code:
package
{
//list of our imports these are classes we need in order to
//run our application.
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
//our Engine class it extends MovieClip
public class imageLoader extends MovieClip
{
private var imageName:String;
private var imgLoader:Loader;
private var mc_preLoader:preLoader = new preLoader();
private var mcEr:JHerror = new JHerror(); // Error MC displays error and sends email to admin
private var mc_target:Object;
private var imgWidth:Number;
private var imgHeight:Number;
private var imgX:Number;
private var imgY:Number;
public function imageLoader(url:String,img:String,target_mc:Object,Width:Number,Height:Number,X:Number,Y:Number):void
{
imgWidth = Width;
imgHeight = Height;
imgX = X;
imgY = Y;
mc_target = target_mc;
imageName = img;
imgLoader=new Loader();
imgLoader.load(new URLRequest(url));
//Add a listener to update the preloader on the image's progress
imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,imageLoading);
//Adding a listener that will update the preloader once the image has been loaded
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded);
imgLoader.addEventListener ( IOErrorEvent.IO_ERROR, handleIOError );
imgLoader.addEventListener ( SecurityErrorEvent.SECURITY_ERROR, handleSecurityError );
stage.addChild(mc_preLoader);
}
public function imageLoaded(evt:Event):void
{
imgLoader.width = imgWidth;
imgLoader.height = imgHeight;
imgLoader.x = imgX;
imgLoader.y = imgY;
mc_target.addChild(imgLoader);
mc_preLoader.killSelf();
}
public function imageLoading(evt:ProgressEvent):void
{
// Get the current download progress
var loaded:Number=evt.bytesLoaded/evt.bytesTotal;
// Send progress info to "preloader" movie clip
updateProgress(loaded);
}
public function updateProgress(percent:Number)
{
percent = Math.floor(percent*100);
var loadedString:String = percent.toString();
mc_preLoader.txtImagePreload.text = "Loading " + imageName + " Please Wait " + loadedString + " %";
}
function handleIOError ( event:IOErrorEvent ):void
{
addChild(mcEr); // if error display error message mc
mcEr.init("Store() : State() : IOErrorEvent catch: " + event.text);
trace ( "Load failed: IO error: " + event.text );
}
function handleSecurityError ( event:SecurityErrorEvent ):void
{
addChild(mcEr); // if error display error message mc
mcEr.init( "Store() : State() : Load failed: Security Error: " + event.text );
trace ( "Load failed: Security Error: " + event.text );
}
public function killSelf():void
{
parent.removeChild(this);
}
}
}
Thanks for any help