2010-06-01 72 views
0

我已经通过多个线程了解了此错误,但尚未能够将其应用于计算我的情况...Flash按钮不起作用:TypeError:错误#1009:无法访问空对象引用的属性或方法

我的Flash文件是一个约5秒的动画。然后,每个图层的最后一个关键帧(第133帧)中都有一个按钮。我的Flash文件应该停留在最后一个关键帧上,并且您应该能够点击6个按钮中的任意一个以导航到我网站中的另一个html页面。

这里是我已经应用于其中的按钮存在(在一个单独的层中的帧的动作脚本,见截图于:http://www.footprintsfamilyphoto.com/wp-content/themes/Footprints/images/flash_buttonissue.jpg

stop(); 


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"); 
} 

bc_btn1.addEventListener(MouseEvent.CLICK, babieschildren); 
bc_btn2.addEventListener(MouseEvent.CLICK, babieschildren); 


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

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


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"); 
} 

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

当我测试影片,我得到此错误输出框:“TypeError:错误#1009:无法访问空对象引用的属性或方法”。

测试影片停止在适当的框架上,但按钮不执行任何操作(无URL打开,并且当测试影片上的按钮被点击时,跟踪语句不会显示在输出框中)

你可以在这里查看.swf文件:www.footprintsfamilyphoto.com/portfolio

我相信,所有的6个按钮都在适当的帧(帧133)的存在,所以我不认为这是什么导致1009错误。

我也尝试每次删除三个函数/ addEventListener节中的每一节并进行测试,并且我仍然每次都得到1009错误。如果我删除除“stop()”行之外的所有操作脚本,那么我不会收到1009错误。

任何想法??我对Flash很新,所以如果我没有澄清我需要的东西,请告诉我!


更新:我得到这个事做与我的文件的建设,而不是代码本身的感觉 - 如果任何人有更多截图/信息的建议,我可以在这里包括可能有助于揭示任何构造上的缺陷,让我知道,我会很高兴捕获/发布它们。我只是不确定要作为Error 1009的来源寻找什么?我已经确认并重新确认了我的实例名称......所有按钮都存在于动作脚本所在的同一帧中(第133帧)。我不进口任何外部物体...

任何建议将不胜感激!

回答

0

我使用CS3重建样本,至少对我来说它按预期工作 和你的代码看起来是正确的以及.. 我能想象到的唯一的事情就是 没有一个实例名称(如“bc_btn1 “) 在您的时间轴上的每个KEYFRAME上。

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

关于

0

非常感谢您的回复!如果我有CS3的副本,考虑到CS4给我的头痛,我会非常乐意回复!

我最终将我的文件发送给朋友/闪存大师直接修复。在这里粘贴他的回应,以防其他人有帮助!老实说,我有点惊讶它正在为你做这件事,尤其是因为我可以在没有任何问题的情况下从Flash创作环境运行程序 - 只有当你真正从外部启动swf才会发生问题。

你肯定是在正确的轨道上检查这些按钮的实例。看起来好像是因为按钮被添加到该框架中,几乎在框架脚本应该运行的同时,它仅仅是按顺序排列。所以它试图在程序知道它们存在之前在按钮上调用addEventListener。

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

下面是我现在用于该框架的代码。看看这是否有帮助 - 现在它适用于我。现在我将不得不详细阅读这些内容,以了解处理此问题的推荐技术。

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"); 
} 
2

我有完全相同的错误,我在这里读一些有关SWF没有赶上按钮实例上时,即使是在同一框架上,它是exaclty这一点。

我只是扩大了按钮1帧之前的动作和工作!

相关问题