Flash AS 事件属性:可以使用 for 循环跟踪它们吗?

发布于 2024-09-30 19:30:18 字数 441 浏览 3 评论 0原文

我想知道是否可以使用 for (或 for every)循环来跟踪输出窗口的事件属性。我知道我可以一次性跟踪该事件,如下所示:

function myFunct (evt:IOErrorEvent):void
{
    trace(evt);
}

不幸的是,在某些情况下(例如很长的 URL 路径)读取起来有点疯狂,因此我想稍微重新格式化它以在其自己的行上显示每个属性,像这样:

function URLLoader_IOError (evt:IOErrorEvent):void
{
    for each(var prop in evt)
    {
        trace(prop)
    }
}

当然,这个示例在输出窗口中没有显示任何内容。我是否在函数中遗漏了某些内容,或者这根本不可行?

谢谢!

I was wondering if it was possible to use a for (or for each) loop to trace the properties of an event to the output window. I know I can trace the event in one go, like this:

function myFunct (evt:IOErrorEvent):void
{
    trace(evt);
}

Unfortunately this gets a little crazy to read in some situations, such as a long URL path, so I would like to reformat it a bit to show each property on its own line, something like this:

function URLLoader_IOError (evt:IOErrorEvent):void
{
    for each(var prop in evt)
    {
        trace(prop)
    }
}

Of course, this example isn't showing anything in the output window. Am I missing something in the function or is this just not doable?

Thanks!

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

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

发布评论

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

评论(1

东北女汉子 2024-10-07 19:30:18

我建议您找到要跟踪的命名属性并专门跟踪它们。有用的属性有 errorIdtexttype。也可能是eventPhase

正如您的代码所示,您将尝试将对象转换为字符串表示形式。例如,trace 应该如何处理 currentTarget 属性?您真的关心 IOErrorEventbubbles 属性吗?还是‘构造者’?

或者,您可以在循环中进行大量测试,以确定您正在处理的数据类型,并将其一些属性转换为字符串以进行跟踪,但最终您仍然需要使用调试器深入检查对象。

I suggest you find the named properties you want to trace and trace those specifically. Properties that would be useful are errorId, text and type. Possibly eventPhase as well.

As your code stands, you will be trying to convert objects to string representations. What is trace supposed to do with the currentTarget property, for example? And do you really care about the bubbles property of IOErrorEvent? Or 'constructor'?

Alternatively, you can do a lot of testing in your loop to determine what kind of data type you're dealing with, and convert some of its properties to strings for tracing, but at the end of the day you'll still have to use the debugger to examine objects in depth.

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