2011-01-29 01:39:36 +00:00
|
|
|
package
|
|
|
|
{
|
|
|
|
import flash.display.BitmapData;
|
|
|
|
import flash.display.Bitmap;
|
|
|
|
import flash.display.Loader;
|
|
|
|
import flash.display.LoaderInfo;
|
|
|
|
import flash.events.Event;
|
|
|
|
import flash.events.EventDispatcher;
|
|
|
|
import flash.events.FileListEvent;
|
|
|
|
import flash.events.IOErrorEvent;
|
|
|
|
import flash.filesystem.File;
|
|
|
|
import flash.net.URLRequest;
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @author jjp
|
|
|
|
*/
|
|
|
|
public class Imgdir extends EventDispatcher
|
|
|
|
{
|
|
|
|
public static const LOADED: String = "ImgLoaded";
|
|
|
|
private var dir: File;
|
2011-02-01 16:31:41 +00:00
|
|
|
private var mpurpf_bmp: Object;
|
2011-02-02 00:45:57 +00:00
|
|
|
private var rgdirname: Object;
|
2011-01-29 01:39:36 +00:00
|
|
|
public function Imgdir(url: String)
|
|
|
|
{
|
|
|
|
trace("imgdir: " + url);
|
|
|
|
this.dir = new File(url);
|
|
|
|
this.dir.addEventListener(FileListEvent.DIRECTORY_LISTING, OnDirUpdate);
|
2011-02-01 16:31:41 +00:00
|
|
|
this.mpurpf_bmp = { };
|
2011-02-02 00:45:57 +00:00
|
|
|
this.rgdirname = { };
|
2011-01-29 01:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function Update() : void
|
|
|
|
{
|
|
|
|
this.dir.getDirectoryListingAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function OnDirUpdate(ev:FileListEvent) : void
|
|
|
|
{
|
|
|
|
for each (var file: File in ev.files)
|
|
|
|
{
|
2011-02-02 00:45:57 +00:00
|
|
|
if (file.isDirectory && !rgdirname[file.name])
|
2011-01-29 01:39:36 +00:00
|
|
|
{
|
2011-02-02 00:45:57 +00:00
|
|
|
var urpd: String = file.name + "/";
|
|
|
|
rgdirname[urpd] = true;
|
|
|
|
dispatchEvent(new EvNewImg(LOADED, urpd, null));
|
2011-01-29 01:39:36 +00:00
|
|
|
}
|
2011-02-02 00:45:57 +00:00
|
|
|
else if (!file.isDirectory && /\.(png|gif|jpg|jpeg)$/i.test(file.name) && !mpurpf_bmp[file.name])
|
2011-01-29 01:39:36 +00:00
|
|
|
LoadBmp(file, OnBmpLoaded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static function LoadBmp(file: File, dgOnLoad: Function, dgOnFail: Function = null):void
|
|
|
|
{
|
|
|
|
var loader : Loader = new Loader();
|
|
|
|
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
|
|
|
|
function (evBmp: Event) : void {
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var bmp : BitmapData = Bitmap(LoaderInfo(evBmp.target).content).bitmapData;
|
|
|
|
dgOnLoad(bmp, file);
|
|
|
|
}
|
|
|
|
catch(e:*) {}
|
|
|
|
} );
|
|
|
|
if (dgOnFail === null)
|
|
|
|
dgOnFail = function(): void { }; // ignore errors
|
|
|
|
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, dgOnFail);
|
|
|
|
loader.load(new URLRequest(file.url));
|
|
|
|
}
|
|
|
|
private function OnBmpLoaded(bmp: BitmapData, file: File) : void
|
|
|
|
{
|
2011-02-01 16:31:41 +00:00
|
|
|
mpurpf_bmp[file.name] = bmp;
|
2011-01-29 01:39:36 +00:00
|
|
|
this.dispatchEvent(new EvNewImg(LOADED, file.name, bmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|