0 Replies Latest reply on Jun 4, 2007 12:50 AM by marko2009-pEoprz

    Flex custom preloader

      I was wondering if someone would be able to help me with passing an event to my custom preloader.

      My main Flex application talks to a remote ColdFusion CFC using WebServices. By the time I get a result back from the webservice, the built-in Flex preloader has already reached 100%, which leaves my application hanging until I get a result back from the webservice.

      I have designed my custom preloader and I'm calling it like this:
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" preloader="myComponents.MyPreloader" creationComplete="init();">

      What I want to do now, is keep the preloader on the screen until I get a result back from the webservice, and then remove it.

      My init() function calls the webservice and when a result comes back I am dispatching an event, but it is not heard inside MyPreloader class.

      Here is a portion of my code for main.mxml:
      private function init():void {
      var ws:WebService = new WebService();
      ws.wsdl = " http://localhost:8300/remote/test.cfc?wsdl";
      ws.useProxy = false;
      ws.showBusyCursor = true;
      ws.echo("Bla Bla");

      ws.addEventListener(ResultEvent.RESULT, myResult);
      ws.addEventListener(FaultEvent.FAULT, loadError);

      private function myResult(result:ResultEvent):void {
      trace("dispatching event");
      dispatchEvent(new Event("dataLoaded"));

      private function loadError(fault:FaultEvent):void {

      And here is a portion of my custom preloader class MyPreloader.as:
      package myComponents
      import flash.display.*;
      import flash.utils.*;
      import flash.events.*;
      import flash.net.*;
      import mx.preloaders.*;
      import mx.events.*;
      import mx.controls.ProgressBar;

      public class MyPreloader extends DownloadProgressBar
      implements IPreloaderDisplay
      // Define a Loader control to load the SWF file.
      private var dpbImageControl:flash.display.Loader;

      public var ldr:LoaderGraphic;

      public function MyPreloader() {
      ldr = new LoaderGraphic();

      // Specify the event listeners.
      override public function set preloader(preloader:Sprite):void {
      // Listen for the relevant events
      ProgressEvent.PROGRESS, handleProgress);
      Event.COMPLETE, handleComplete);

      FlexEvent.INIT_PROGRESS, handleInitProgress);
      FlexEvent.INIT_COMPLETE, handleInitComplete);
      preloader.addEventListener("dataLoaded", dataLoaded);

      public function dataLoaded(event:Event):void {
      // preloader finished
      dispatchEvent(new Event(Event.COMPLETE));

      Get the idea of what I'm trying to do? :)

      My problem is that "dataLoaded" does not penetrate MyPreloader Class

      Your help would be much appreciated.