AS3 -TypeError #1009 - 有什么简单的方法可以找出*哪个*对象引用为空? [英] AS3 -TypeError #1009 - any easy way to find out *which* object reference is null?

查看:23
本文介绍了AS3 -TypeError #1009 - 有什么简单的方法可以找出*哪个*对象引用为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都会时不时地收到TypeError #1009 无法访问空对象引用的属性或方法"——没什么大不了的,但有时调试会令人沮丧.

We all get "TypeError #1009 Cannot access a property or method of a null object reference" now and then - no big deal, but sometimes frustrating to debug.

Flash 为您提供调用堆栈(这是一个开始),但由您来确定空对象的位置 - 是否有可能找出究竟是哪个引用正在抛出错误?

Flash gives you the call stack (which is a start), but leaves it up to you to figure out where the null object is - is it possible to find out exactly which reference is throwing the error?

鉴于以下(容易出错)函数:

Given the following (error prone) function:

function nullObjectReferenceError():void
    {
        var obj:Object;
        var prop:* = obj.nonExistentProperty;
    }

而不仅仅是来自 TypeError 的调用堆栈,我想跟踪如下内容:无法访问 obj.nonExistentProperty 处的空对象引用的属性或方法强>" - 这甚至可能吗?

Rather than just the call stack from the TypeError, I'd like to trace something like: "Cannot access a property or method of a null object reference at obj.nonExistentProperty" - Is this even possible?

推荐答案

如果您在 Flash IDE 的发布设置"下选中允许调试",它会为您提供代码中导致错误的行号.

If you check Permit Debugging under Publish Settings in the Flash IDE, it gives you the line number in your code causing the error.

这篇关于AS3 -TypeError #1009 - 有什么简单的方法可以找出*哪个*对象引用为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆