The treeData Variable declaration and Calling the init function - XML
The Flex Tree control is amazingly useful when building applications, especially if you're dealing with hierarchical data. To learn how to add the power of this intuitive organizational component to your developer's toolbox, keep reading.
The treeData variable is declared with the following line:
The [Bindable] keyword tells the compiler that the treeData Array can bind to a control such as a data provider. So, if the Array is changed, the control will be updated automatically. In this article, we only scratch the surface in covering information on bindings and data providers. For more information see on data providers see Flex Quick Start: Building an advance user interface on adobe.com.
To call our init function, we've added an attribute on the mx:Application tag. This attribute is "preinitialize." The value of he attribute is the name of our function 'init()'.
Here is what the code looks like:
The preinitialize event is one of many events that are triggered when an application launches. In particular, I've selected preinitialize because it occurs before the control is added to the layout. In this way, I can be assured that the data provider is fully populated so that when the control is displayed, the data will be present.
The result of changing XMLList out for a Array is the same. Using one over the other really depends on what the source of your data is and how it is organized. It is common for flex/flash apps to connect to web services to retrieve their data, and thankfully ActionScript is capable is using both of these types.