AS3 --- TypeError:错误#1009:无法访问空对象引用的属性或方法

时间:2011-01-11 17:34:08

标签: flash actionscript-3

单击按钮转到另一帧后,Flash给我这个错误。在我收到错误后,某些按钮不会到达目的地,而是只执行任何操作。

错误如下:

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

以下是第39帧的代码:

stop();

winter_btn.addEventListener(MouseEvent.CLICK, buttonClick1);
function buttonClick1(event:MouseEvent):void{
gotoAndPlay(39);
};

spring_btn_boys.addEventListener(MouseEvent.CLICK, buttonClick10);
function buttonClick10(event:MouseEvent):void{
gotoAndPlay(114);
};

fall_btn_boys.addEventListener(MouseEvent.CLICK, buttonClick11);
function buttonClick11(event:MouseEvent):void{
gotoAndPlay(135);
}; 

3 个答案:

答案 0 :(得分:3)

我看了你的flash电影/应用程序,以下是你问题的解决方案:

.alt text

上图是flash电影/应用程序时间轴的屏幕截图。在第39帧,您收到错误“TypeError:错误#1009:无法访问空对象引用的属性或方法。在wmhssports_fla :: MainTimeline / frame39()”。您接受了这一点,因为此时spring_btn_girls按钮的实例spring_btn为空。要解决此问题,请在第34帧上为spring_btn按钮的实例提供实例名称“spring_btn_girls”。

答案 1 :(得分:0)

您要链接的其中一个按钮不存在(实例名称错误?)或者不在您正在编码的帧上。

正如约翰所说,试试trace(winter_btn, spring_btn, fall_btn);。返回null的那个是您想要纠正的那个。

答案 2 :(得分:0)

你可以实际设置它,它会告诉你什么行代码引发了错误。这是我写的关于这个主题的博客文章:http://mykola.bilokonsky.net/2010/08/get-line-numbers-on-runtime-errors-in-flash/

祝你好运!