preloading flex 的问题

在我proloading AIR时遇到,TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spark.components::WindowedApplication/enterFrameHandler()[E:\dev\4.x\frameworks\projects\airspark\src\spark\components\WindowedApplication.as:2349]

提示,stage = null ,最后发现要在FlexEvent.INIT_PROGRESS的处理函数中加点东西如下:

if(FlexGlobals.topLevelApplication != null)
   {
    FlexGlobals.topLevelApplication.addEventListener(Event.ENTER_FRAME ,onWindowedApplicationEnterFrame, false, int.MAX_VALUE);
    (FlexGlobals.topLevelApplication).addEventListener(Event.ADDED_TO_STAGE, onWindowedApplicationAddedToStage, false, int.MAX_VALUE);
    trace("SCREEN: ", FlexGlobals.topLevelApplication.screen);
   }

接下来写两个回调函数

private var pendingWindowedApplicationEnterFrameEvent:Event;

 

private function onWindowedApplicationEnterFrame(event:Event):void
  {
   pendingWindowedApplicationEnterFrameEvent = event.clone();
   event.stopImmediatePropagation();
  }
  
  private function onWindowedApplicationAddedToStage(event:Event):void
  {
   FlexGlobals.topLevelApplication.addEventListener(Event.ADDED_TO_STAGE, onWindowedApplicationAddedToStage, false);
   FlexGlobals.topLevelApplication.removeEventListener(Event.ENTER_FRAME, onWindowedApplicationEnterFrame, false);
   
   // dispatch pending enter frame event
   dispatchEvent(pendingWindowedApplicationEnterFrameEvent);
   
  }

然后就OK了

你可能感兴趣的:(Flex,Access,AIR)