AS3 ImageLoader Class

Load bitmap images in OOP concept. Simple and easy custom image loader class,

import <package name>.imageload.imageLoad;

var myImage:imageLoad;
var myImagePath:String = “(add your image path here)”;
myImage = new imageLoad(myImagePath, 1, 600, 400, 0, 0);
addChild(myImage);

imageLoad Class (Flash AS3)

package map.imageload{

import caurina.transitions.*;
import flash.filters.DropShadowFilter;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.LoaderInfo;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.events.ProgressEvent;
import flash.events.Event;

public class imageLoad extends Sprite {
private var img:String;
private var img_loader:Loader;
private var imgWidth:uint;
private var imgHeight:uint;
private var loadProgress_txt:TextField;
private var format:TextFormat;
private var font:Font;
private var pBar:ProgressBar;
private var X:int;
private var Y:int;

function imageLoad(img_image:String, img_id:uint, img_width:uint, img_height:uint, X:int, Y:int):void {

this.name = “image”+img_id;
this.img = img_image;
this.imgWidth = img_width;
this.imgHeight = img_height;
this.X = X;
this.Y = Y;

loadImage();

//text format
format = new TextFormat();
format.font = “Arial”
format.color = 0xFFFFFF;
format.size = 9;

//progress text
loadProgress_txt = new TextField();
loadProgress_txt.x = imgWidth/2 – loadProgress_txt.width/2;
loadProgress_txt.y = imgHeight/2 + 5;
loadProgress_txt.embedFonts = false;
loadProgress_txt.selectable = false;
loadProgress_txt.autoSize = TextFieldAutoSize.CENTER;
loadProgress_txt.defaultTextFormat = format;

}

//load image
private function loadImage():void {

// progress bar
pBar = new ProgressBar();
pBar.mode = ProgressBarMode.MANUAL;
pBar.y = imgHeight/2 – pBar.height/2;
pBar.x = imgWidth/2 – pBar.width/2;
//addChild(pBar);

img_loader = new Loader();
img_loader.load(new URLRequest(img));
img_loader.alpha = 0;
img_loader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
img_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
img_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,showLoadResult);
img_loader.mouseEnabled = false;
img_loader.x = X;
img_loader.y = Y;

addChild(img_loader);
}

//preloader events
private function showPreloader(evt:Event):void {
//addChild(loadProgress_txt);
}

private function showProgress(evt:ProgressEvent):void {
var percentLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
loadProgress_txt.text = Math.round(percentLoaded * 100) + “%”;
pBar.setProgress(evt.bytesLoaded, evt.bytesTotal);
}

//once image has loaded show
private function showLoadResult(evt:Event):void {
//removeChild(loadProgress_txt);
//removeChild(pBar);
Tweener.addTween(img_loader, {alpha:1, time:1, transition:”easeOut”});
img_loader.removeEventListener(ProgressEvent.PROGRESS, showProgress);
img_loader.removeEventListener(Event.COMPLETE, showLoadResult);
}
}
}

Load bitmap images in OOP concept. Simple and easy custom image loader class,

import <package name>.imageload.imageLoad;

var myImage:imageLoad;

var myImagePath:String = “(add your image path here)”;

myImage = new imageLoad(myImagePath, 1, 600, 400, 0, 0);

addChild(myImage);

I'm a highly experienced and mature creative professional from Colombo, Sri Lanka. My passion for strong, unique design and creative expression drive me to do what I do. I strive to push the boundaries of design across all mediums to create new and immersive users experiences. My creative inspiration comes from the worlds of design, film, photography and the time spent with colleagues, friends and family. My flexible and dynamic approach allows me to provide my professional service, responsive and effective solutions to their business needs.

Posted in ActionScript 3

Leave a comment

More Info

Enter your email address to subscribe to my blog and receive notifications of new posts by email.

Join 1 other subscriber
  • An error has occurred; the feed is probably down. Try again later.