Browse Source

added Lambda.indexOf and concat
wait for stageWidth != 0 before flash boot

Nicolas Cannasse 15 years ago
parent
commit
12ba76302c
3 changed files with 47 additions and 13 deletions
  1. 3 1
      doc/CHANGES.txt
  2. 26 0
      std/Lambda.hx
  3. 18 12
      std/flash9/Boot.hx

+ 3 - 1
doc/CHANGES.txt

@@ -12,8 +12,10 @@
 	php: fixed EReg.replace (issue 194)
 	php: FileSystem.readDirectory now skips '.' and '..' to be consistent with neko (issue 226)
 	flash9 : add trace text on stage (always over current and subclips)
-	flash9 : delay SWF initialization until it's added on stage (disable with -D dontWaitStage)
+	flash9 : delay SWF initialization until it's added on stage and stageWidth > 0
+	         (this can be disabled with -D dontWaitStage)
 	all : added haxe.Timer.measure
+	all : added Lambda.indexOf and Lambda.concat
 
 2010-08-14: 2.06
 	neko : change serializer to be able to handle instances of basic classes from other modules

+ 26 - 0
std/Lambda.hx

@@ -156,4 +156,30 @@ class Lambda {
 		return !it.iterator().hasNext();
 	}
 
+	/**
+		Returns the index of the item in the given Iterable, depending on the order of the Iterator.
+		Returns -1 if the item was not found.
+	**/
+	public static function indexOf<T>( it : Iterable<T>, v : T ) : Int {
+		var i = 0;
+		for( v2 in it ) {
+			if( v == v2 )
+				return i;
+			i++;
+		}
+		return -1;
+	}
+
+	/**
+		Returns a list containing all items of 'a' followed by all items of 'b'
+	**/
+	public static function concat<T>( a : Iterable<T>, b : Iterable<T> ) : List<T> {
+		var l = new List();
+		for( x in a )
+			l.add(x);
+		for( x in b )
+			l.add(x);
+		return l;
+	}
+
 }

+ 18 - 12
std/flash9/Boot.hx

@@ -76,27 +76,33 @@ class Boot extends flash.display.MovieClip, implements Dynamic {
 		lines = new Array();
 		var c = if( mc == null ) this else mc;
 		flash.Lib.current = c;
-		if( init != null ) {
-			try {
-				untyped if( c.stage != null && c.stage.align == "" )
-					c.stage.align = "TOP_LEFT";
-			} catch( e : Dynamic ) {
-				// security error when loading from different domain
-			}
-			#if dontWaitStage
+		if( init != null )
+			start();
+	}
+
+	function start() {
+		var c = flash.Lib.current;
+		try {
+			untyped if( c.stage != null && c.stage.align == "" )
+				c.stage.align = "TOP_LEFT";
+		} catch( e : Dynamic ) {
+			// security error when loading from different domain
+		}
+		#if (dontWaitStage || swc)
 			init();
-			#else
+		#else
 			if( c.stage == null )
 				c.addEventListener(flash.events.Event.ADDED_TO_STAGE, doInitDelay);
+			else if( c.stage.stageWidth == 0 )
+				untyped __global__["flash.utils.setTimeout"](start,1);
 			else
 				init();
-			#end
-		}
+		#end
 	}
 
 	function doInitDelay(_) {
 		flash.Lib.current.removeEventListener(flash.events.Event.ADDED_TO_STAGE, doInitDelay);
-		init();
+		start();
 	}
 
 	public static function enum_to_string( e : { tag : String, params : Array<Dynamic> } ) {