Created
April 1, 2013 07:30
-
-
Save sonygod/5283660 to your computer and use it in GitHub Desktop.
GC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import flash.events.IEventDispatcher; | |
import haxe.ds.ObjectMap; | |
import haxe.io.Error; | |
import flash.display.BitmapData; | |
import flash.display.Bitmap; | |
import flash.display.MovieClip; | |
import flash.events.Event; | |
using Lambda; | |
class Bm { | |
public static var bitmapdatas:Array<BitmapData> = []; | |
public static var bitmapPool:ObjectMap<BitmapData,Bitmap>=new ObjectMap<BitmapData,Bitmap>(); | |
public static var mcPool:ObjectMap<String,MovieClip>=new ObjectMap<String,MovieClip>(); | |
public static function addBitmapData(data:BitmapData):Void { | |
bitmapdatas.push(data); | |
} | |
//don't know why can not be call when using Bm | |
public static function addEventListener2(target:IEventDispatcher,type:String, listener:Event->Void, ?useCapture:Bool = false, ?priority:Int = 0, ?useWeakReference:Bool = false):Void { | |
target.addEventListener(type, listener, useCapture, priority, useWeakReference); | |
} | |
public static function clearAll():Void { | |
#if debug | |
trace("bitmapdata length"+bitmapdatas.length); | |
#end | |
bitmapdatas.map(function (data:BitmapData):Void { | |
var b:Bitmap; | |
if (bitmapPool.exists(data)) { | |
b= bitmapPool.get(data); | |
if (b.parent!=null) { | |
b.parent.removeChild(b); | |
} | |
} data.dispose(); data = null; | |
b = null; } ); | |
bitmapdatas = []; | |
mcPool.map(function (data:MovieClip):Void { | |
if (data.parent!=null) { | |
data.stop(); | |
data.parent.removeChild(data); | |
data.mouseChildren = false; | |
data.mouseEnabled = false; | |
data = null; | |
} | |
}); | |
mcPool = new ObjectMap<String,MovieClip>(); | |
bitmapPool=new ObjectMap<BitmapData,Bitmap>(); | |
} | |
public static function addBitmap(data:Bitmap):Void { | |
bitmapPool.set(data.bitmapData, data); | |
} | |
public static function addMc(data:MovieClip):Void { | |
mcPool.set(data.name, data); | |
} | |
} | |
abstract BitmapData2(BitmapData) to BitmapData { | |
private inline function new(a:BitmapData) { | |
this = a; | |
Bm.addBitmapData(a); | |
} | |
@:from static public inline function fromBitmapData(a:BitmapData):BitmapData2 { | |
return new BitmapData2(a); | |
} | |
} | |
abstract Bitmap2(Bitmap) to Bitmap { | |
private inline function new(a:Bitmap) { | |
this = a; | |
Bm.addBitmapData(a.bitmapData); | |
} | |
@:from static public inline function fromBitmap(a:Bitmap):Bitmap2 { | |
return new Bitmap2(a); | |
} | |
} | |
abstract MovieClip2(MovieClip) to MovieClip { | |
private inline function new(a:MovieClip) { | |
this = a; | |
Bm.addMc(a); | |
} | |
@:from static public inline function fromBitmap(a:MovieClip):MovieClip2 { | |
return new MovieClip2(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment