Flex application initialization sequence

Source: Internet
Author: User

The initial requirement is to load the relevant configuration information at the appropriate time of application initialization for subsequent initialization. The backend uses blazeds to communicate with the entire system based on remoteobject.
The initialization sequence of the Flex application is preloader-> systemmanager-> flexapplication started...
Then:
Preinitialize
Triggered before all initialization. No sub-component is defined, but the component variables can be referenced.
Initialize
When all child components are generated, no widgets are rendered at this time point.
CreationComplete
The widget is defined and displayed in the list.
ApplicationComplete
All components are initialized and displayed.

InPreinitializeApplication initialization cannot be controlled, so you needPreinitializeThe previous configuration information loading of preloader can achieve the goal. By Rewriting sparkdownloadprogressbar and listening to flexevent. preloader_doc_frame_ready events, you can intercept the application before initialization.

Override public function set preloader (value: Sprite): void {super. preloader = value; _ preloader = value; // intercept value before app initialization. addEventListener (FlexEvent. PRELOADER_DOC_FRAME_READY, applicationInit, false, int. MAX_VALUE);}/*** load permission configuration and other information **/private function applicationInit (event: FlexEvent): void {// pause app initialization event. stopImmediatePropagation (); suspend = true; var con: NetConnection = new NetConnection (); con. object Encoding = ObjectEncoding. AMF3con. connect (". /messagebroker/amf "); con. addEventListener (NetStatusEvent. NET_STATUS, function (): void {}); con. addEventListener (SecurityErrorEvent. SECURITY_ERROR, function (): void {}); con. addEventListener (IOErrorEvent. IO_ERROR, function (): void {}); con. addEventListener (AsyncErrorEvent. ASYNC_ERROR, function (): void {}); con. call ("systemFlex. getUserInfo ", new Responder (sysInitHand Ler, faultHandler);}/*** configure loading and processing, and set initialization information **/private function sysInitHandler (data: Object ): void {// if it is loaded to the information if (data. uid) {// initialize the user information var model: GlobalModel = GlobalModel. getInstance (); model. uid = data. uid; model. username = data. username; if (data. privileges) {var privileges: XMLList = new XMLList (data. privileges); // permission tree model. privileges = privileges; // ArrayCollection cannot be used because the flex resources are not loaded when this method is enabled. Preinitialize initialization of the app // var privilegesArr: ArrayCollection = new ArrayCollection (privileges..node.@id.toXMLString (). split ("\ n"); // msgBox. text = "Start permission control... "; // start permission control // SecurityControler. start (privilegesArr); msgBox. text = "User Information Initialization is complete. "; _ preloader. removeEventListener (FlexEvent. PRELOADER_DOC_FRAME_READY, applicationInit); suspend = false; // re-initiate the event and continue app initialization _ preloader. dispatchEvent (new FlexEvent (FlexEvent. P RELOADER_DOC_FRAME_READY);} else {msgBox. text = "permission information loading failed, initialization ended! ";}} Else {msgBox. text =" An error occurred while loading the initialization information. Initialization ended! ";}} Private function faultHandler (info: Object): void {msgBox. text =" failed to load system and user configuration information. Initialization ended! \ N "+ info. message ;}

The flexevent. preloader_doc_frame_ready event can be used to execute code before application initialization. However, because the application is not fully loaded at this time, many Mx and spark components cannot be used normally, you need to use the classes and methods provided under the flash package for the purpose.
At first, I used remoteobject to load data, but an error was reported because ResourceManager was not fully initialized. In addition, data types such as arraycollection In the MX or spark package cannot be used. Therefore, when transmitting data in the form of objects, avoid converting the data to these types. In the project, a framework called flexsecurity is used for UI permission control. The arraycollection used for initialization is unavailable in the listening code, without affecting the function, you can change the permission initialization to the preinitialize of the application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.