I have a Flex application that loads some data from the database. During this I want my 开发者_开发技巧custom preloader stay visible.
The dilemma is: When I postpone the dispatchEvent(new Event(Event.COMPLETE))
in the FlexEvent.INIT_COMPLETE
handler, the loading will never happen because the next frame is not entered.
How can I keep the loader running until all the data is fully loaded?
A preloader is basically a sprite. All flex components extend sprites so you can actually continue to work with sprites pretty easily. I'm not sure how difficult it would be to override the part of the application framework that REMOVES that pre-loader sprite.. however, I think you can add the sprite back to the stage... using a custom component .
You probably have to create a UIComponent and add your preloader component so that you can use it with states. Then set your NEW UIComponent to the default state.
The following is "psuedo" code off the top of my head.
public class MyFlexPreLoader extends UIComponent{
private var var preloader:YourBasePreLoader; //This is the preloader you're already using
override protected function createChildren(){
//Add the Preloader here!
preloader = new YourBasePreLoader();
addChild(preloader);
}
//Also add event listeners to manipulate your preloader to show the progress of loading stuff from DB
}
Then in your app
<comp:MyFlexPreLoader includeIn="preloading"/>
Now when you're done change the currentState of the app away from pre-loading. You may need to override a few more methods in UIComponent to get it working right.
精彩评论