Skip to content
dolph1n edited this page Jan 11, 2013 · 13 revisions

ObjectBuilder is an ActionScript3 language extension, that is intended to automate complicated objects creation in declarative style. In other words, ObjectBuilder is a template related a class. This template can contain:

##ObjectBuilder Blocks ###class properties block

Class properties block is intended to fill out all the possible properties of a class in a simple and compact declarative mode.

Sprite{ 
 x : 200; 
 y : 300; 
};

###event description block

Event description block contains all information related with events handling of a class.

TextField{ 
 text : "Hello World"; 
 onClick : {e => 
   this.setTextFormat(TextFormat(<font:String>){ 
     font : "_serif"; 
     size : 20; 
     align : TextFormatAlign.LEFT; 
   }); 
 }; 
}

###children block

Children block contains ObjectBuilders for all children of a parent object. This feature is available only for DisplayObject children.

Sprite{
  children : 
    [ 
      TextField{ 
        text : "Hello World!"; 
      } 
    ]; 
  children : 
    [ 
      SimpleButton(<upState:DisplayObject>){ 
        name : "myButton"; 
      } 
   ]; 
};

###init block

Init block is executed on instance creation. Extremely useful when you need this statement.

Sprite{ 
  init : { => 
    with (this.graphics) { 
      beginFill(0x000000, .4); 
      drawRect(0, 0, 600, 400); 
    } 
  }; 
};

###constructor parameters block

Optional block, that appears only if the parent class has parameters.

public function myClass(a : int, b : int) {
  ...
}

public function method() : void
{
  myClass(1, 2){ 
    <<...>> 
  }; 
}

Clone this wiki locally