2
0
Эх сурвалжийг харах

fixed getElementById when structure is not finalized (before scene allocation)

ncannasse 12 жил өмнө
parent
commit
cb31656354

+ 13 - 0
h2d/comp/Component.hx

@@ -32,6 +32,8 @@ class Component extends Sprite {
 	public function getElementById(id:String) {
 	public function getElementById(id:String) {
 		if( this.id == id )
 		if( this.id == id )
 			return this;
 			return this;
+		if( !allocated )
+			return getElementByIdRec(this, id);
 		for( c in components ) {
 		for( c in components ) {
 			var c = c.getElementById(id);
 			var c = c.getElementById(id);
 			if( c != null )
 			if( c != null )
@@ -40,6 +42,17 @@ class Component extends Sprite {
 		return null;
 		return null;
 	}
 	}
 	
 	
+	function getElementByIdRec( s : h2d.Sprite, id : String ) : Component {
+		var c = flash.Lib.as(s, Component);
+		if( c != null && c.id == id )
+			return c;
+		for( s in s.childs ) {
+			var c = getElementByIdRec(s, id);
+			if( c != null ) return c;
+		}
+		return null;
+	}
+	
 	function set_needRebuild(v) {
 	function set_needRebuild(v) {
 		needRebuild = v;
 		needRebuild = v;
 		if( v && parentComponent != null && !parentComponent.needRebuild )
 		if( v && parentComponent != null && !parentComponent.needRebuild )