Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is "int main()" in my Flex application?
    primarykey
    data
    text
    <p>Well, not literally, of course, but:</p> <p>I'm new to Flex and I'm trying to figure out where to put the code that I want to run when my app starts. In my example, I have a tree control defined in the markup, and I have AS code that can populate it from a local file or a webservice. How do I bind the one to the other such that when the control is created, the code is run?</p> <p>The examples I have found in the documentation all use event handlers, i. e. they put 'creationComplete="myInitFunction(evt)"' in the control's opening tag. That would mean I write a little glue function that initializes things.</p> <p>Now, as I have understood it, the Markup is really converted into AS classes internally. So can I not just define a class that is instantiated by the engine and put my startup code in the constructor? Maybe even like, extending the Tree class?</p> <p><strong>EDIT</strong>:</p> <p>Months later, I'm a lot wiser. After trying to abuse the constructors of extended component classes, I had to learn that Flex doesn't expect the constructors to do much - certainly not loading data off the network.</p> <p>The component life cycle explanation in "Programming Flex 3" was really helpful. Now, my constructors are all empty, and I'm overriding the life cycle methods, such as <code>createChildren</code> for a lot of things, and use events for anything that involves latency or depends on externalities, especially network stuff.</p> <p>For example, I use <code>creationComplete</code> to initiate an asynchronous network request (using <code>HTTPService</code>), when that returns there are ResultEvent and FaultEvent handlers, the ResultEvent updates a data model to which I data-bound my controls. This is seemingly very Flex-y and works great.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload