Browse Source

flash9 support

Pascal Peridont 19 years ago
parent
commit
41b52b3b5f
3 changed files with 50 additions and 12 deletions
  1. 22 5
      std/Hash.hx
  2. 22 5
      std/IntHash.hx
  3. 6 2
      std/StringTools.hx

+ 22 - 5
std/Hash.hx

@@ -34,7 +34,9 @@ class Hash<T> {
 		Creates a new empty hashtable.
 		Creates a new empty hashtable.
 	**/
 	**/
 	public function new() : Void {
 	public function new() : Void {
-		#if flash
+		#if flash9
+		h = new flash.utils.Dictionary();
+		#else flash
 		h = untyped __new__(_global["Object"]);
 		h = untyped __new__(_global["Object"]);
 		#else neko
 		#else neko
 		h = untyped __dollar__hnew(0);
 		h = untyped __dollar__hnew(0);
@@ -84,7 +86,9 @@ class Hash<T> {
 		a [null] value versus no value.
 		a [null] value versus no value.
 	**/
 	**/
 	public function exists( key : String ) : Bool {
 	public function exists( key : String ) : Bool {
-		#if flash
+		#if flash9
+		return untyped h.hasOwnProperty(key);
+		#else flash
 		return untyped h["hasOwnProperty"](key);
 		return untyped h["hasOwnProperty"](key);
 		#else js
 		#else js
 		try {
 		try {
@@ -107,7 +111,11 @@ class Hash<T> {
 		there was such entry.
 		there was such entry.
 	**/
 	**/
 	public function remove( key : String ) : Bool {
 	public function remove( key : String ) : Bool {
-		#if flash
+		#if flash9
+		if( untyped !h.hasOwnProperty(key) ) return false;
+		untyped __delete__(h,key);
+		return true;
+		#else flash
 		if( untyped !h["hasOwnProperty"](key) ) return false;
 		if( untyped !h["hasOwnProperty"](key) ) return false;
 		untyped __delete__(h,key);
 		untyped __delete__(h,key);
 		return true;
 		return true;
@@ -126,7 +134,9 @@ class Hash<T> {
 		Returns an iterator of all keys in the hashtable.
 		Returns an iterator of all keys in the hashtable.
 	**/
 	**/
 	public function keys() : Iterator<String> {
 	public function keys() : Iterator<String> {
-		#if flash
+		#if flash9
+		return untyped (__keys__(h)).iterator();
+		#else flash
 		return untyped (__keys__(h))["iterator"]();
 		return untyped (__keys__(h))["iterator"]();
 		#else js
 		#else js
 		var a = new Array<String>();
 		var a = new Array<String>();
@@ -147,7 +157,14 @@ class Hash<T> {
 		Returns an iterator of all values in the hashtable.
 		Returns an iterator of all values in the hashtable.
 	**/
 	**/
 	public function iterator() : Iterator<T> {
 	public function iterator() : Iterator<T> {
-		#if flash
+		#if flash9
+		return untyped {
+			ref : h,
+			it : keys(),
+			hasNext : function() { return this.it.hasNext(); },
+			next : function() { var i = this.it.next(); return this.ref[i]; }
+		};
+		#else flash
 		return untyped {
 		return untyped {
 			ref : h,
 			ref : h,
 			it : keys(),
 			it : keys(),

+ 22 - 5
std/IntHash.hx

@@ -33,7 +33,9 @@ class IntHash<T> {
 		Creates a new empty hashtable.
 		Creates a new empty hashtable.
 	**/
 	**/
 	public function new() : Void {
 	public function new() : Void {
-		#if flash
+		#if flash9
+		h = new flash.utils.Dictionary();
+		#else flash
 		h = untyped __new__(_global["Object"]);
 		h = untyped __new__(_global["Object"]);
 		#else neko
 		#else neko
 		h = untyped __dollar__hnew(0);
 		h = untyped __dollar__hnew(0);
@@ -81,7 +83,9 @@ class IntHash<T> {
 		a [null] value versus no value.
 		a [null] value versus no value.
 	**/
 	**/
 	public function exists( key : Int ) : Bool {
 	public function exists( key : Int ) : Bool {
-		#if flash
+		#if flash9
+		return untyped h.hasOwnProperty(key);
+		#else flash
 		return untyped h["hasOwnProperty"](key);
 		return untyped h["hasOwnProperty"](key);
 		#else js
 		#else js
 		return untyped h[key] != null;
 		return untyped h[key] != null;
@@ -96,7 +100,11 @@ class IntHash<T> {
 		there was such entry.
 		there was such entry.
 	**/
 	**/
 	public function remove( key : Int ) : Bool {
 	public function remove( key : Int ) : Bool {
-		#if flash
+		#if flash9
+		if( untyped !h.hasOwnProperty(key) ) return false;
+		untyped __delete__(h,key);
+		return true;
+		#else flash
 		if( untyped !h["hasOwnProperty"](key) ) return false;
 		if( untyped !h["hasOwnProperty"](key) ) return false;
 		untyped __delete__(h,key);
 		untyped __delete__(h,key);
 		return true;
 		return true;
@@ -114,7 +122,9 @@ class IntHash<T> {
 		Returns an iterator of all keys in the hashtable.
 		Returns an iterator of all keys in the hashtable.
 	**/
 	**/
 	public function keys() : Iterator<Int> {
 	public function keys() : Iterator<Int> {
-		#if flash
+		#if flash9
+		return untyped (__keys__(h)).iterator();
+		#else flash
 		var l : Array<Int> = untyped __keys__(h);
 		var l : Array<Int> = untyped __keys__(h);
 		for( x in 0...l.length )
 		for( x in 0...l.length )
 			l[x] = Std.int(l[x]);
 			l[x] = Std.int(l[x]);
@@ -138,7 +148,14 @@ class IntHash<T> {
 		Returns an iterator of all values in the hashtable.
 		Returns an iterator of all values in the hashtable.
 	**/
 	**/
 	public function iterator() : Iterator<T> {
 	public function iterator() : Iterator<T> {
-		#if flash
+		#if flash9
+		return untyped {
+			ref : h,
+			it : keys(),
+			hasNext : function() { return this.it.hasNext(); },
+			next : function() { var i = this.it.next(); return this.ref[i]; }
+		};
+		#else flash
 		return untyped {
 		return untyped {
 			ref : h,
 			ref : h,
 			it : keys(),
 			it : keys(),

+ 6 - 2
std/StringTools.hx

@@ -36,7 +36,9 @@ class StringTools {
 		Encode an URL by using the standard format.
 		Encode an URL by using the standard format.
 	**/
 	**/
 	public static function urlEncode( s : String ) : String {
 	public static function urlEncode( s : String ) : String {
-		#if flash
+		#if flash9
+		return untyped __global__["encodeURIComponent"](s);
+		#else flash
 		return untyped _global["escape"](s);
 		return untyped _global["escape"](s);
 		#else neko
 		#else neko
 		return new String(_urlEncode(untyped s.__s));
 		return new String(_urlEncode(untyped s.__s));
@@ -50,7 +52,9 @@ class StringTools {
 		Decode an URL using the standard format.
 		Decode an URL using the standard format.
 	**/
 	**/
 	public static function urlDecode( s : String ) : String {
 	public static function urlDecode( s : String ) : String {
-		#if flash
+		#if flash9
+		return untyped __global__["decodeURIComponent"](s.split("+").join(" "));
+		#else flash
 		return untyped _global["unescape"](s);
 		return untyped _global["unescape"](s);
 		#else neko
 		#else neko
 		return new String(_urlDecode(untyped s.__s));
 		return new String(_urlDecode(untyped s.__s));