Create nested layouts with Starling Builder

You can create nested layouts (layout files inside layout files) to reuse layout files. A possible use case is a generic title bar for multiple popups. If you use an external layout for the title bar, then you don't need to duplicate data in multiple popups. When you change the look of the title bar, it will be automatically updated in all the popups that using it.

For Editor

In the editor, goto File → Load External to load in the sub layout file. You need to make sure the sub layout files and their parent layout file are in the same directory.

For Game

In the game, you need to implement IAssetMediator.getExternalData interface to be able to use this feature.

Access external layout params

The params meta data of external layouts created by UIBuilder.load() is preserved in a field called externalParams in the meta data of the its parent container. By accessing it you will have the same level of control of its parent layout.

Data binding for external layout

Since the external layout is created by the parent layout, by default it's not bind to any class. You can call UIBuilder.bind(class_to_bind, externalParams) to bind it to any class you want.

For more information of how to use external layouts, please check out the ExternalElementTest from the demo project at

https://github.com/yuhengh/starling-builder-engine/blob/master/demo-2.x/src/starlingbuilder/demo2/ExternalElementTest.as

  builder/nested-layout.txt · Last modified: 2017/02/21 02:47 by johannh
 
Powered by DokuWiki