After i did the Multi Image Loader AS2.0,
I wanted to make an AS3.0 version of the class.
————
USAGE:
var multi:MultiImageLoader = MultiImageLoader.getInstance();
multi.addEventListener( MultiImageLoader.IMAGE_LOAD_START , onImageStart );
multi.addEventListener( MultiImageLoader.IMAGE_LOAD_PROGRESS , onImageProgress );
multi.addEventListener( MultiImageLoader.IMAGE_LOAD_COMPLETE , onImageComplete );
multi.addEventListener( MultiImageLoader.MULTI_LOAD_START, onMultiStart );
multi.addEventListener( MultiImageLoader.MULTI_LOAD_COMPLETE, onMultiComplete );
multi.store( photoContainer_01, “img/img_01.png”, “myPhotoId” );
multi.store( photoContainer_02, “img/img_02.png”, “myPhotoId2″ );
//Use: image container, image address, image ID ( for later referrence ).
multi.startLoad();
EVENTS:
- IMAGE_LOAD_START
- IMAGE_LOAD_PROGRESS
- IMAGE_LOAD_COMPLETE
- MULTI_LOAD_START
- MULTI_LOAD_COMPLETE
USED CUSTOM EVENT:
- IDEvent
————
MULTI IMAGE LOADER:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
| package nl.rackdoll.loaders
{
import nl.rackdoll.loaders.events.IDEvent;
import flash.display.*;
import flash.events.*;
import flash.net.*;
public class MultiImageLoader extends EventDispatcher
{
//Events:
public static const IMAGE_LOAD_PROGRESS :String = "image_load_in_progress";
public static const IMAGE_LOAD_COMPLETE :String = "image_load_is_complete";
public static const IMAGE_LOAD_START :String = "image_load_has_started";
public static const MULTI_LOAD_START :String = "multi_load_has_started";
public static const MULTI_LOAD_COMPLETE :String = "multi_load_is_complete";
//Public vars:
public var i_progress :Number = 0;
public var sp_currentContainer :Sprite;
public var s_currentAddress :String = "";
//Private vars:
private var multiLoader :Loader;
private var a_images :Array = new Array();
private var i_counter :Number = 0;
//----
//Constructor:
public function MultiImageLoader()
{
trace("MultiImageLoader made!");
setupLoader();
}
//PULICS
public function storeImage( holder:DisplayObject, address:String, id:String ):void
{
var image:Object = new Object();
image.holder = holder;
image.address = address;
image.eventId = id;
a_images.push( image );
}
public function startLoad():void
{
dispatchEvent( new IDEvent( MULTI_LOAD_START ) );
load();
}
//PRIVATES
private function setupLoader():void
{
multiLoader = new Loader();
multiLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, onProgress );
multiLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadComplete );
}
private function load():void
{
if ( i_counter < a_images.length )
{
s_currentAddress = a_images[ i_counter ].address;
dispatchEvent( new IDEvent(IMAGE_LOAD_START, a_images[ i_counter ].eventId, true ) );
multiLoader.load( new URLRequest( a_images[ i_counter ].address) );
}else {
sp_currentContainer = null;
s_currentAddress = "";
a_images = [];
i_counter = 0;
dispatchEvent( new IDEvent( MULTI_LOAD_COMPLETE) );
}
}
private function onProgress( evt:ProgressEvent ):void
{
i_progress = evt.bytesLoaded;
dispatchEvent( new IDEvent( IMAGE_LOAD_PROGRESS, a_images[ i_counter ].eventId , true ) );
}
private function onLoadComplete( evt:Event ):void
{
var image:Bitmap = new Bitmap(evt.target.content.bitmapData);
a_images[ i_counter ].holder.addChild(image);
sp_currentContainer = a_images[ i_counter ].holder;
dispatchEvent( new IDEvent( IMAGE_LOAD_COMPLETE, a_images[ i_counter ].eventId, true ) );
i_counter++;
load();
}
//SINGLETON
private static var _instance:MultiImageLoader;
public static function getInstance():MultiImageLoader
{
if (!_instance) _instance = new MultiImageLoader();
return _instance;
}
}
} |