本文介绍了类型错误:错误#1009 - AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Lemonade_fla::MainTimeline/frame3()[Lemonade_fla.MainTimeline::frame3:48]

从这个片段的code:

buy_sugar.addEventListener(MouseEvent.CLICK, buysugar);
function buysugar(event:MouseEvent):void{
    if (cash1>=0.50){
        buy.play();
        cash1 = cash.text.text;
        cash1 = cash1 - 0.25;
        sugar = sugar_count.text;
        sugar=sugar+16;
    }
}

有没有人有什么原因呢?任何想法

Does anyone have any ideas of why?

推荐答案

在开放问题的评论来看,似乎buy_sugar为空。你相信buy_sugar是在时间轴上一个影片剪辑,从而可以在code被安全地引用,但是如果buy_sugar确实存在,你不会得到这个错误。

Judging by the commentary in the opening question, it seems that buy_sugar is null. You believe that buy_sugar is a movieclip on the timeline, and thus can be safely referenced in your code, but if buy_sugar really existed you wouldn't get this error.

您绝对积极的,buy_sugar存在相同的帧,你正在做的呼叫?

Are you absolutely positive that buy_sugar exists on the same frame as the call you're making?

假设你目前框架3 ...

Let's say you're currently on frame 3...

buy_sugar.addEventListener(Event.FOO, onFoo); // if buy_sugar exists on frame 3, this works.

但是,如果你在第2帧?

But what if you're on frame 2?

gotoAndStop(3);
buy_sugar.addEventListener(Event.FOO, onFoo); // problem... this can fail if buy_sugar exists on 3 but NOT on 2.

请确保您引用实际上剪辑存在于该呼叫被写在框架上,并仔细检查你的实例名的拼写。

Make sure that the clip you're referencing actually exists on the frame in which the call is written, and double-check your instance name spelling.

:

这些图片是pretty的有趣。它似乎是buy_sugar是存在于框架3一个影片剪辑元件,但buy_sugar痕迹为空在框架3的脚本。以下是进一步调试的一些建议。

Those pictures are pretty interesting. It does appear that buy_sugar is a movieclip symbol that exists on frame 3, yet buy_sugar traces as null in your frame 3 script. Here are a few suggestions for further debugging.

  1. 在code,你必须跟踪(buy_sugar);,与更换跟踪(测试buy_sugar presence,buy_sugar,currentFrame);

  1. In the code where you have trace(buy_sugar);, replace it withtrace("testing buy_sugar presence ", buy_sugar, currentFrame);

从舞台的地方切buy_sugar影片剪辑。下面让所有的人一个新层,并粘贴buy_sugar到第1帧的关键帧,不要在该层上添加任何其他关键帧。我们的目标是确保buy_sugar存在在所有时间,在所有的帧。

CUT the buy_sugar movieclip from its place on the stage. Make a new layer below all the others, and paste buy_sugar into the keyframe on frame 1. Don't add ANY other keyframes on that layer. The goal is to make sure the buy_sugar exists at all times, on all frames.

让我知道,你所看到的,当你做到这一点。

Let me know what you see when you do this.

修改

现在,我们已经确定了夹子的可以的,当它存在于所有的帧,飞奔该关键帧以上1至3进行检测,使得夹只存在于框架3仍然是工作?如果是的话,只要将那层左右的地方它会寻找最好的。

Now that we've determined that the clip can be detected when it exists on all frames, scoot that keyframe over from 1 to 3 so that the clip exists only on frame 3. Does it still work? If so, just move that layer around to where it will look nicest.

如果它不工作,再次将那层高达那里的影片剪辑看起来最好的。而不是把剪辑的只有的第3帧中,做出框架3,如果您要它夹一个关键帧,并在所有其它帧都有夹子生活过的舞台可见的地方。这样的哈克,但它工作来解决这个问题。

If it does not work, again move that layer up to where the movieclip will look nicest. Instead of putting the clip only on frame 3, make a keyframe on frame 3 with the clip where you want it, and on all other frames have the clip live somewhere off the visible stage. That's kind of hacky, but it works to solve the problem.

这篇关于类型错误:错误#1009 - AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:16