Display Tree Builder
A declarative language to set up trees of display objects.
var displayTree:DisplayTree = new DisplayTree(); displayTree. uses(rootView). containing. //Adds a Sprite with the name "Menu", containing one //instance of each FullScreenButton and EditButton a (Sprite). withTheName ("Menu"). containing. a (FullScreenButton). an (EditButton). end. //Adds 3 instances of Container, each with //a single instance of Icon times (3). a (Container). containing. an (Icon). end. end.finish();
The DSL only allows terms where they make sense (e.g. you can not place
times(x)). This is especially useful in IDEs with
code completion. [Warning: This feature is currently a bit shaky, so
don't lean on it to heavily.]
Creating display objects from data
It is also possible to create a display object for every item in a collection, using the item to initialize the object.
displayTree. uses (rootView). containing. a (Sprite). forEveryItemIn (["Spades", "Hearts", "Diamonds", "Clubs"]). withTheProperty ("name"). setToThe. item end.finish();
The collection can be an
IIterable or an
IIterator (the last two from the
AS3Commons Collections library)