Actionscript 3 闪光按钮不';t Work:TypeError:Error#1009:无法访问空对象引用的属性或方法

Actionscript 3 闪光按钮不';t Work:TypeError:Error#1009:无法访问空对象引用的属性或方法,actionscript-3,flash,button,typeerror,cs4,Actionscript 3,Flash,Button,Typeerror,Cs4,我已经通读了几个关于这个错误的帖子,但是还不能应用它来了解我的情况 我的flash文件是一个大约5秒的动画。然后,每个层的最后一个关键帧(帧133)中都有一个按钮。我的flash文件应该在最后一个关键帧停止,您应该能够单击6个按钮中的任何一个来导航到我网站中的另一个html页面 下面是我应用于按钮所在帧的动作脚本(在单独的层上,请参见以下屏幕截图: 测试电影时,在输出框中出现以下错误: TypeError:Error#1009:无法访问null的属性或方法 对象引用 测试电影确实会在相应的帧上停

我已经通读了几个关于这个错误的帖子,但是还不能应用它来了解我的情况

我的flash文件是一个大约5秒的动画。然后,每个层的最后一个关键帧(帧133)中都有一个按钮。我的flash文件应该在最后一个关键帧停止,您应该能够单击6个按钮中的任何一个来导航到我网站中的另一个html页面

下面是我应用于按钮所在帧的动作脚本(在单独的层上,请参见以下屏幕截图:

测试电影时,在输出框中出现以下错误:

TypeError:Error#1009:无法访问null的属性或方法 对象引用

测试电影确实会在相应的帧上停止,但按钮不会执行任何操作(没有打开URL,并且当在测试电影上单击按钮时,跟踪语句不会显示在输出框中)

您可以在此处查看.swf文件:www.footprintsfamilyphoto.com/portfolio

我确信所有6个按钮都存在于适当的帧(第133帧)中,因此我不认为这是导致1009错误的原因

我还尝试一次删除三个function/addEventListener部分中的每一部分并进行测试,但每次都会出现1009错误。如果删除除“stop()”行之外的所有动作脚本,则不会出现1009错误

有什么想法吗?我对Flash非常陌生,所以如果我没有澄清我需要澄清的事情,请告诉我


更新:我感觉这与我的文件结构有关,而不是代码本身。如果有人对更多截图/信息有建议,我可以在这里提供,这可能有助于揭示任何结构缺陷,让我知道,我很乐意捕捉/发布它们。我只是不确定要看什么g作为错误1009的来源?我已经确认并重新确认了我的实例名称…所有按钮都存在于动作脚本所在的同一帧中(第133帧)。我没有导入任何外部对象


如果您有任何建议,我们将不胜感激。

我使用CS3重新构建了您的样本,至少对我来说,它可以按预期工作 而且您的代码看起来也正确。。 我唯一能想象的就是 没有实例名称(例如“bc_btn1”) 在时间轴中的每个关键帧上

在这种情况下,我得到了同样的错误。。 所以也许你应该检查一下


问候

非常感谢您的回复!如果我有一份CS3,我会非常愿意回复,因为CS4一直让我头疼

最后,我把我的文件直接发送给一位朋友/flash大师来修复。将他的回复粘贴到这里,以防对其他人有所帮助

老实说,我有点惊讶它会这样对你,特别是因为我可以在Flash创作环境中毫无问题地运行程序——只有当你实际从外部启动swf时,问题才会发生

您检查这些按钮实例的方法肯定是正确的。似乎是因为按钮被添加到了该框架中,而框架脚本应该在运行的同时运行,它只是发现自己出现了问题。因此,它试图在程序知道按钮存在之前调用按钮的addEventListener

我不能说我的解决方案是否正确,但它应该可以工作并且速度相对较快。当程序到达该帧时,我会让它检查以确保每个按钮都存在。我将此检查放在一个函数中,该函数由ENTER_frame事件调用,只要e程序正在运行(这与我们调用的stop()命令无关)。一旦检查通过,即没有任何按钮为空,我将为所有按钮添加事件侦听器,并删除ENTER_帧的侦听器,以便此checker方法停止运行

这是我现在为这个框架准备的代码。看看这是否有帮助-它现在对我有效。我现在要多读一点,看看推荐什么技术来处理这个问题

import flash.events.Event;

stop ();

//listen for the Flash player's ENTER_FRAME event...
this.addEventListener(Event.ENTER_FRAME, onEnterFrame, false);

//and call this checker function continually until all of the buttons are accounted for
function onEnterFrame(e:Event):void {
 if (bc_btn1 != null && bc_btn2 != null && f_btn1 != null && f_btn2 != null && cw_btn1 != null && cw_btn2 != null){
  bc_btn1.addEventListener(MouseEvent.CLICK, babieschildren);
  bc_btn2.addEventListener(MouseEvent.CLICK, babieschildren);

  f_btn1.addEventListener(MouseEvent.CLICK, fams);
  f_btn2.addEventListener(MouseEvent.CLICK, fams);

  cw_btn1.addEventListener(MouseEvent.CLICK, couplesweddings);
  cw_btn2.addEventListener(MouseEvent.CLICK, couplesweddings);

  //clean up the enter frame listener so that this function no longer gets called
  this.removeEventListener(Event.ENTER_FRAME, onEnterFrame, false);
 }
}



function babieschildren(event:MouseEvent):void 
{ 
    trace("babies children method was called!!!");
    var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/babies-children"); 
    navigateToURL(targetURL, "_self"); 
}


function fams(event:MouseEvent):void 
{ 
    trace("families method was called!!!");
    var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/families"); 
    navigateToURL(targetURL, "_self"); 
}


function couplesweddings(event:MouseEvent):void 
{ 
    trace("couples weddings method was called!!!");
    var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/couples-weddings"); 
    navigateToURL(targetURL, "_self"); 
}

我有完全相同的错误,我在这里读到一些关于swf没有及时赶上button实例的东西,即使它在同一帧上,这是很明显的

我只是在actionscript之前扩展了button 1框架,并成功了

import flash.events.Event;

stop ();

//listen for the Flash player's ENTER_FRAME event...
this.addEventListener(Event.ENTER_FRAME, onEnterFrame, false);

//and call this checker function continually until all of the buttons are accounted for
function onEnterFrame(e:Event):void {
 if (bc_btn1 != null && bc_btn2 != null && f_btn1 != null && f_btn2 != null && cw_btn1 != null && cw_btn2 != null){
  bc_btn1.addEventListener(MouseEvent.CLICK, babieschildren);
  bc_btn2.addEventListener(MouseEvent.CLICK, babieschildren);

  f_btn1.addEventListener(MouseEvent.CLICK, fams);
  f_btn2.addEventListener(MouseEvent.CLICK, fams);

  cw_btn1.addEventListener(MouseEvent.CLICK, couplesweddings);
  cw_btn2.addEventListener(MouseEvent.CLICK, couplesweddings);

  //clean up the enter frame listener so that this function no longer gets called
  this.removeEventListener(Event.ENTER_FRAME, onEnterFrame, false);
 }
}



function babieschildren(event:MouseEvent):void 
{ 
    trace("babies children method was called!!!");
    var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/babies-children"); 
    navigateToURL(targetURL, "_self"); 
}


function fams(event:MouseEvent):void 
{ 
    trace("families method was called!!!");
    var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/families"); 
    navigateToURL(targetURL, "_self"); 
}


function couplesweddings(event:MouseEvent):void 
{ 
    trace("couples weddings method was called!!!");
    var targetURL:URLRequest = new URLRequest("http://www.footprintsfamilyphoto.com/portfolio/couples-weddings"); 
    navigateToURL(targetURL, "_self"); 
}