Pour les Container et UIComponent, Adobe Flex va dispatcher les Event preinitialize, initialize et creationComplete. Quand un enfant est initialisé, son parent peut alors l'être. Ce qui signifie qu'un enfant sera toujours initialisé avant sont parent. Cependant, l'Event creationComplete ne sera accessible par les enfants que lorsque tous ses parents auront été initialisés. Prenons un exemple :
Application
Canvas
VBox
Button
TextInput
HBox
Label
Image
Dans l'ordre chronologique on a donc :
1. Application preinitialize;
2. Canvas preinitialize;
3. VBox preinitialize;
4. Button preinitialize;
5. Button initialize;
6. TextInput preinitialize;
7. TextInput initialize;
8. VBox initialize;
9. HBox preinitialize;
10. Label preinitialize;
11. Label initialize;
12. Image preinitialize;
13. Image initialize;
14. HBox initialize;
15. Canvas initialize;
16. Application initialize;
17. Button creationComplete;
18. TextInput creationComplete;
19. Label creationComplete;
20. Image creationComplete;
21. VBox creationComplete;
22. HBox creationComplete;
23. Canvas creationComplete;
24. Application creationComplete.
Source / Exemple :
<?xml version="1.0"?>
<!--
Mikaflex.com ©
You have the right to copy and use this example, but not to sell.
A link to my website would be well-appreciated :)
-->
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
viewSourceURL="srcview/index.html"
width="100%" height="100%"
xmlns:viewSource="com.mikaflex.viewSource.*"
xmlns:footer="com.mikaflex.footer.*"
preinitialize="Alert.show('preinitialized Application')"
initialize="Alert.show('initialized Application')"
creationComplete="Alert.show('creationComplete Application')">
<!-- Script -->
<mx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</mx:Script>
<!-- Canvas -->
<mx:Canvas
preinitialize="Alert.show('preinitialize Canvas')"
initialize="Alert.show('initialize Canvas')"
creationComplete="Alert.show('creationComplete Canvas')"
width="100%" height="100%">
<!-- VBox -->
<mx:VBox x="20"
preinitialize="Alert.show('preinitialize VBox')"
initialize="Alert.show('initialize VBox')"
creationComplete="Alert.show('creationComplete VBox')"
styleName="boxMain" horizontalAlign="center" width="400" height="100" >
<!-- Button -->
<mx:Button
preinitialize="Alert.show('preinitialize Button')"
initialize="Alert.show('initialize Button')"
creationComplete="Alert.show('creationComplete Button')"
/>
<!-- TextInput -->
<mx:TextInput
preinitialize="Alert.show('preinitialize TextInput')"
initialize="Alert.show('initialize TextInput')"
creationComplete="Alert.show('creationComplete TextInput')"
/>
</mx:VBox>
<!-- HBox -->
<mx:HBox preinitialize="Alert.show('preinitialize HBox')"
initialize="Alert.show('initialize HBox')"
creationComplete="Alert.show('creationComplete HBox')"
horizontalAlign="center" width="400" height="100" >
<!-- Label -->
<mx:Label
preinitialize="Alert.show('preinitialize Label')"
initialize="Alert.show('initialize Label')"
creationComplete="Alert.show('creationComplete Label')"
/>
<!-- Image -->
<mx:Image
preinitialize="Alert.show('preinitialize Image')"
initialize="Alert.show('initialize Image')"
creationComplete="Alert.show('creationComplete Image')"
/>
</mx:HBox>
</mx:Canvas>
</mx:Application>
Conclusion :
Etant donné que l'upload de fichiers ne fonctionne pas. Retrouvez cet exemple sur mon site afin de le télécharger, à l'adresse suivante :
http://www.mikaflex.com/2009/01/24/event-preinitilize-initialize-creationcomplete/
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.