2 Replies Latest reply on Oct 5, 2008 7:12 PM by SiHoop

    Cannot use a stage event handler

    SiHoop Level 1
      Today seems to be 'one of those days'. Nothing is working properly and I don't know if it's me or my machine. The code below comes from the Adobe site-- it will not work for me unless I comment out the event handler; this has been the story for all my attempts to use an event handler with stage.

      Here's my error message:
      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at Demo/init()[C:\Documents and Settings\sxh12\My Documents\Flex Builder 3\Demo\src\Demo.mxml:18]

      Am I doing something wrong or is my Flex playing up?
        • 1. Re: Cannot use a stage event handler
          g-s-b Level 1

          It is a matter of timing: the stage is not immediately initialized and available to you.
          You can use a preloader to wait for the stage to catch up, or as here, use the applicationComplete event instead.

          Here is the trace results of the code below:

          [SWF] C:\...\TestingStuff.swf - 556,906 bytes after decompression
          preInitialize - stage.addEventListener is NOT YET a Function!
          initialize - stage.addEventListener is NOT YET a Function!
          creationComplete - stage.addEventListener is NOT YET a Function!
          applicationComplete - stage.addEventListener is a Function.

          • 2. Re: Cannot use a stage event handler
            SiHoop Level 1
            Thank you! I was not aware these event handlers existed.