Flash 按钮不起作用:TypeError:错误 #1009:无法访问空对象引用的属性或方法

发布于 2024-09-03 08:06:11 字数 2257 浏览 9 评论 0原文

我已经阅读了有关此错误的多个线程,但无法应用它来弄清楚我的情况...

我的 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:无法访问 null 的属性或方法 对象引用。

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

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

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

我还尝试一次删除三个 function/addEventListener 部分并进行测试,但每次仍然收到 1009 错误。如果我删除除“stop ()”行之外的所有操作脚本,那么我不会收到 1009 错误。

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


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

任何建议将不胜感激!

I've read through several threads about this error, but haven't been able to apply it to figure out my situation...

My flash file is an approx 5 second animation. Then, the last keyframe of each layer (frame #133) has a button in it. My flash file should stop on this last key frame, and you should be able to click on any of the 6 buttons to navigate to another html page in my website.

Here is the Action Script that I have applied to the frame in which the buttons exist (on a separate layer, see screenshot at: 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);

When I test the movie, I get this error in the output box:

TypeError: Error #1009: Cannot access a property or method of a null
object reference.

The test movie does stop on the appropriate frame, but the buttons don't do anything (no URL is opened, and the trace statements don't show up in the output box when the buttons are clicked on the test movie).

You can view the .swf file here: www.footprintsfamilyphoto.com/portfolio

I'm confident that all 6 buttons do exist in the appropriate frame (frame 133), so I don't think that's what's causing the 1009 error.

I also tried deleting each of the three function/addEventListener sections one at a time and testing, and I still got the 1009 error every time. If I delete ALL of the action script except for the "stop ()" line, then I do NOT get the 1009 error.

Any ideas?? I'm very new to Flash, so if I haven't clarified something that I need to, let me know!


Update: I'm getting the feeling that this has something to do with the construction of my file rather than the code itself - if anyone has suggestions for more screenshots/information I could include here that might help to reveal any constructional flaws, let me know, and I'll be glad to capture/post them. I'm just not sure what to be looking for as the source of Error 1009? I've confirmed and reconfirmed my instance names... all buttons exist in the same frame where the action script is located (frame 133). i'm not importing any external objects...

Any suggestions would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

始终不够 2024-09-10 08:06:11

我遇到了完全相同的错误,我在这里读到一些关于 swf 没有按时赶上按钮实例的内容,即使它位于同一帧上,而且确实如此。

我只是将按钮在动作脚本之前扩展了 1 帧,然后就成功了!

I had the exact same error and I read here something about the swf not catching up to the button instance on time even though it's on the same frame and it was exaclty that.

I simply extended the button 1 frame before the actionscript and worked!

孤独陪着我 2024-09-10 08:06:11

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

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

问候

i rebuild your sample using CS3 and at least for me it works as expected
and your code looks correct as well..
the only thing i could imagine is that
there is not an instance-name (e.g. "bc_btn1")
on EVERY KEYFRAME in your timeline.

in this case i'm getting the same error..
so maybe you should check that.

regards

深海少女心 2024-09-10 08:06:11

非常感谢您的回复!如果我有一份 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"); 
}

Thanks so much for your response! If I had a copy of CS3, I'd be more than willing to revert, given the headaches CS4 has been giving me!

I ended up sending my file over to a friend/flash guru to fix directly. Pasting his response here in case it's helpful to anyone else!

To be honest, I'm a little suprised it's doing this to you, especially since I can run the program from the Flash authoring environment without problem - it's only when you actually launch the swf externally that the problem happens.

You were definitely on the right track with checking those button instances. It seems as if because the buttons are added to that frame, at about the same time the frame script is supposed to run, it's just catching itself out of order. So it's trying to call addEventListener on the buttons before the program knows they exist.

I can't say whether my solution is the correct one, but it should work and be relatively quick. When the program reaches that frame, I'm having it check to make sure each of those buttons exists. I put this check inside a function that gets called by the ENTER_FRAME event, which will happen continuously at your program's framerate as long as the program is running (this is independent of the stop() command we're calling). As soon as the check passes, meaning that none of the buttons are null, I add the event listeners for all of the buttons and remove the listener for the ENTER_FRAME so that this checker method stops running.

Here's the code I have for that frame now. See if this helps - it works for me now. I'm going to have to read up on this a little more now to see what techniques are recommended for dealing with this.

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"); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文