PDA

View Full Version : Controlling Instantiation order using initstage


antun
04-24-2003, 02:37 PM
Note: You will not notice the difference in instantiation time in the examples given in this tip - they are simply too small (and therefore fast at initializing).

As your applications get more and more complex, you're going to want to control the time that various elements appear on the canvas while the app is initializing.

By default, views will wait until they are all initialized and then display. This can be frustrating if view instantiation takes a long time, as the application will appear blank. To cause a view to be initialized before the bulk of views, use the initstage="early" attribute:


<canvas>
<view bgcolor="red" width="50" height="50"
initstage="early" />
<view bgcolor="blue" width="50" height="50" y="75" />
</canvas>


A good use for this would be to show some UI elements while the rest of the application is starting up, so that the user does not get impatient.

To cause a view to be instantiated after the bulk of views, use the initstage="late" attribute:


<canvas>
<view bgcolor="red" width="50" height="50"
initstage="early" />
<view bgcolor="blue" width="50" height="50" y="75" />
<view bgcolor="green" width="50" height="50" y="150"
initstage="late" />
</canvas>


This is handy when an application is large and slow to start up, and you want to defer the instantiation of some views (which the user might not come to until a few clicks into the application), so that the application appears sooner.

By default a view's initstage is "normal". Constraints cannot be resolved across init stages.

Enjoy!

ows
04-25-2003, 11:02 AM
Originally posted by antun
Constraints cannot be resolved across init stages.

Actually this works:

<canvas>
<simplelayout axis="y"/>
<window initstage="late" x="sibling.x"/>
<window name="sibling"/>
</canvas>

(drag the bottom window, and the top drags with it), but this doesn't:

<canvas>
<simplelayout axis="y"/>
<window initstage="early" x="sibling.x"/>
<window name="sibling"/>
</canvas>


A constraint can refer to an object in an earlier initstage (or in the same initstage), but not in a later initstage.