Created
April 2, 2013 01:50
-
-
Save sonygod/5289356 to your computer and use it in GitHub Desktop.
gc realse 有效
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; | |
using Reflect; | |
class Event2 { | |
public var listener :Event->Void; | |
public var useCapture :Bool; | |
public var priority :Int; | |
public var useWeakReference:Bool; | |
public var type:String; | |
public var target:IEventDispatcher; | |
public function new (target:IEventDispatcher,type:String,listener:Event->Void, ?useCapture:Bool = false, ?priority:Int = 0, ?useWeakReference:Bool = false) { | |
this.target = target; | |
this.type = type; | |
this.listener = listener; | |
this.useCapture = useCapture; | |
this.priority = priority; | |
this.useWeakReference = useWeakReference; | |
} | |
} | |
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 var eventMap:ObjectMap < IEventDispatcher, Array<Event2> >= new ObjectMap < IEventDispatcher, Array<Event2> > (); | |
//public static v | |
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 { | |
var eventsArray:Array<Event2> = []; | |
if (eventMap.exists(target)) { | |
eventsArray = eventMap.get(target); | |
}else { | |
eventMap.set(target, eventsArray); | |
} | |
var e:Event2 = new Event2(target,type,listener,useCapture,priority,useWeakReference); | |
eventsArray.push(e); | |
target.addEventListener(type, listener, useCapture, priority, useWeakReference); | |
} | |
public static function clearAll():Void { | |
eventMap.map(function (data:Array<Event2>) { | |
trace("data.length" + data.length); | |
data.map(function (e:Event2) { | |
trace("type"+e.type); | |
e.target.removeEventListener(e.type, e.listener, e.useCapture); | |
e = null; | |
}); | |
data = null; } ); | |
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 = []; | |
eventMap = new ObjectMap < IEventDispatcher, Array<Event2> > (); | |
mcPool = new ObjectMap<String,MovieClip>(); | |
bitmapPool=new ObjectMap<BitmapData,Bitmap>(); | |
} | |
public static function addBitmap(data:Bitmap):Void { | |
bitmapPool.set(data.bitmapData, 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment