Skip navigation
Currently Being Moderated

Flex two-phase preloader - problem preloading AIR

Jul 24, 2010 10:35 AM

Hi all,


I ran into a problem preloading a Flex AIR project. I guess a lot of you are familiar with the 2-phase preloading prinicple of Flex. You defer dispatching FlexEvent.INIT_COMPLETE and Event.COMPLETE to a moment thats suits you. I can get this to work fine with regular Flex projects, but when using this preloading technique with a Flex AIR project I get the following error:


TypeError: Error #1009: Cannot access a property or method of a null object reference. at mx.core::WindowedApplication/enterFrameHandler()[C:\autobuild\3.5.0\f rameworks\projects\airframework\src\mx\core\ 6]


This happens because WindowedApplication.creationCompleteHandler adds an enterFrameHandler:


    private function creationCompleteHandler(event:Event):void
        addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        _nativeWindow = systemManager.stage.nativeWindow;


and WindowedApplication.ennterFrameHandler tries to access the stage:


      private function enterFrameHandler(e:Event):void
        removeEventListener(Event.ENTER_FRAME, enterFrameHandler);

        // If nativeApplication.nativeApplication.exit() has been called,
        // the window will already be closed.
        if (stage.nativeWindow.closed)


The red line of code throws the error mentioned above (its line 2526 of WindowedApplication) Because the preloader defers dispatching FlexEvent.INIT_COMPLETE and Event.COMPLETE the main application is not yet on the stage!


The only way I can get the 2-phase Flex preloading working for preloading a Flex AIR application is not to defer the dispatching of the events. But I need to defer them to apply some animation to the preloader (fade-out).


Are there any known solutions for this problem? Any help is greatly appreciated!





  • Currently Being Moderated
    Jul 25, 2010 12:05 AM   in reply to

    That bug will be fixed in 3.6.  I think you can add your own high priority

    handler and stopImmediatePropagation on the event.

    Mark as:
  • Currently Being Moderated
    Jul 25, 2010 9:40 PM   in reply to

    Here's the bug:


    I wouldn't catch CREATION_COMPLETE, I would catch the ENTER_FRAME going to

    the app, test if stage == null and call stopImmediatePropagation if it is.

    Mark as:
  • Currently Being Moderated
    Jul 26, 2010 10:00 AM   in reply to

    Thanks for the points.  I think you could have skipped the added to stage

    handler and simply tested if stage != null in the enterFrame handler and

    removed the enterframe listener if true.

    Mark as:
  • Currently Being Moderated
    Jun 14, 2013 10:31 AM   in reply to

    Brilliant thanks a lot man works like a charm!

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points