tags:

views:

92

answers:

2

Hi,

Below is the overriden on complete function for a preloader in Flex.

private function initComplete(e:Event):void
  {
   //dispatchEvent(new Event(Event.COMPLETE));
   cp.status.text="Configuring... Please Wait";
  }

What I want to do is when the app has finsihed loading I want to change the preloaders text to "configuring". Then I want to go and do a bunch of setup stuff in my code.

Once I've done all the setup I wanted how can I get the Preloader to dispatch its Event.complete from else where in my code?

I tried Application.application.preloader but it comes up null.

So I guess my question really is how to access a preloader from anywhere in my application. Would a better approach be to have all setup classes as members of my preloader class?

A: 

The component LifeCycle does specific stuff in a specific order, and the near final element is to make the component visible.

It sounds to me like you want to defer this setting of visible to true to do other stuff. But, I imaging if you were making use of the component LifeCycle this would be a non-issue.

What sort of app init stuff do you need to do?

www.Flextras.com
the app init stuff I want to do is basically just the downlaoding and parsing of an xml file and then parsing of mp3s based on that
dubbeat
Use a ViewStack then. One view can be your "Configuring" message that also takes care of the data loading and processing. The second view can be your actual UI. When your configuring is done; switch the selectedIndex of the ViewStack.
www.Flextras.com
thats a handy little solution
dubbeat
A: 

One thing that might help is a Model-View-Controller pattern. Are you using a framework for your application like Mate, Swiz, or Cairngorm?

If you were using Mate, for example, you could do something like this:

  • Create an AppStateManager class with a property (e.g. applicationState)
  • Create an EventMap with an EventHandler for the FlexEvent.INITIALIZE event. In this handler, set the AppStateManager.applicationState to something like "CONFIGURING"
  • Your EventMap has an injector that injects the applicationState property into a view. The injector listens for changes to this property and updates the view. In this case it might just be injected into your main view.
  • In the main view, you have a public bindable property also called applicationState that gets injected by Mate.
  • In the setter for this property, you can have an if/then or a switch that does different tasks depending on the state. For example, if applicationState == "COMPLETE", then this.preloader.dispatchEvent(Event.COMPLETE) or something like that.

The details are pseudo-sketched out but the idea is to use Flex's bindings to notify view components when changes have been made, and to have shared objects that maintain state. Not sure if that's what you're looking for...

Brian