Specifications

CHAPTER 5
106
<mx:Form>
<mx:FormItem label="first:">
<mx:HBox id="box1" creationPolicy="none" width="200" height="50"
borderStyle="solid" backgroundColor="#CCCCFF">
<mx:Button label="Button 1"/>
<mx:Button label="Button 2"/>
</mx:HBox>
</mx:FormItem>
<mx:FormItem label="fourth:">
<mx:HBox id="box2" creationPolicy="none" width="200" height="50"
borderStyle="solid" backgroundColor="#CCCCFF">
<mx:Button label="Button 3"/>
<mx:Button label="Button 4"/>
</mx:HBox>
</mx:FormItem>
<mx:FormItem label="second:">
<mx:HBox id="box3" creationPolicy="none" width="200" height="50"
borderStyle="solid" backgroundColor="#CCCCFF">
<mx:Button label="Button 5"/>
<mx:Button label="Button 6"/>
</mx:HBox>
</mx:FormItem>
<mx:FormItem label="third:">
<mx:HBox id="box4" creationPolicy="none" width="200" height="50"
borderStyle="solid" backgroundColor="#CCCCFF">
<mx:Button label="Button 7"/>
<mx:Button label="Button 8"/>
</mx:HBox>
</mx:FormItem>
</mx:Form>
<mx:Button label="Create Later" click="doCreate();"/>
</mx:Application>
In some cases, the addToCreationQueue() method does not act as you might expect. The reason is that if the
instantiation queue is empty, the first container to be put in that queue triggers the creation process of its children.
Other containers might subsequently be added to the queue, but the instantiation of the first container added has
already been triggered, regardless of the value of its
preferredIndex property. The result is that an item might
not have the lowest
preferredIndex value, but because no other containers are in the queue, Flex begins creating
that container. Flex cannot stop instantiating the first container once it starts.
In the following example, although the redBox container has the highest preferredIndex, Flex creates its
children first because the queue was empty when Flex encountered this line in the code. By the time redBox is
complete, the other containers will be in the queue, and Flex proceeds with the next lowest item in the queue; in
this case, the whiteBox container, followed by blueBox and, finally, greenBox.
function doCreate():void {