2011-12-19 102 views
0

我想用動畫片段跟蹤鼠標的X位置。AS3:無法訪問空對象引用的屬性

我迄今所做的:

public class LuckyHitBeta extends MovieClip { 


    var ballReady:ballReady_mc; 



private function liveIcon():void { 
      ballReady=new ballReady_mc(); 
      addChild(ballReady); 
      ballReady.y=1; 
     } 

private function onEnterFrm(e:Event):void 
    {   
     ballReady.x=mouseX; 

    } 

} 

運行時錯誤:

TypeError: Error #1009: Cannot access a property or method of a null object reference. 
at LuckyHitBeta/onEnterFrm() 

回答

2

我沒有看到你調用函數liveIcon()。看起來enterFrame事件發生在ballready初始化之前。

+0

謝謝,我不得不放置liveIcon();在主要功能上。現在它工作了! – 2011-12-19 22:56:42

1

我想它的意思ballReadyNULL

我會做類似

private function onEnterFrm(e:Event):void 
{   
    if (ballReady) { 
     ballReady.x=mouseX; 
    } 
} 
相關問題