2011-06-19 136 views
-1

我有2个类。TypeError:错误#1009:无法访问空对象引用的属性或方法

a类,b类。

等级a编号,并传递给等级b。

但是,当在类B中定义类a时,Flash throw TypeError:错误#1009:无法访问空对象引用的属性或方法。

这是在闪存中的丘比特错误。

我有在类2功能,

A类:

public function ClassAConstractor():void{ 
stage.addEventListener(MouseEvent.MOUSE_DOWN , OnMouseDown); 
stage.addEventListener(MouseEvent.MOUSE_UP , OnMouseUp); 
} 

B类:

mmm = new ClassAConstractor(); // << when i want define class a in b 

在类constractor功能的那些功能。 当我删除这2行,问题解决了,但我需要2行。 此问题显示当我在类b中定义类a时。 但是当我没有任何定义在类B类没有问题。并且运作良好。

我知道STAGE的闪存错误。但我不知道如何解决这个问题。

回答

1

这听起来像你试图访问阶段之前,它可用。使用Event.ADDED_TO_STAGE事件。

package 
{ 
//Imports 
import flash.display.Sprite; 
import flash.events.Event; 

//Class 
public class MyClass extends Sprite 
    { 
    //Constructor 
    public function MyClass() 
     { 
     //trace(stage.stageWidth); 
     //too early to call the stage, unless MyClass is the Document Class 

     addEventListener(Event.ADDED_TO_STAGE, init); 
     } 

    //Initialization 
    private function init(evt:Event):void 
     { 
     removeEventListener(Event.ADDED_TO_STAGE, init); 
     trace(stage.stageWidth); 
     } 
    } 
} 
+0

工作吧!这是真的.thx – ewfwefewfewf

+0

这帮了我一个类似的问题,我遇到了错误:#1009。我将外部.swf加载到我的主文件夹中,并且每当加载的.swf文件类时都会引发此错误。感谢名单 – Cleanshooter

相关问题