Flash AS 事件属性:可以使用 for 循环跟踪它们吗?
我想知道是否可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您找到要跟踪的命名属性并专门跟踪它们。有用的属性有
errorId
、text
和type
。也可能是eventPhase
。正如您的代码所示,您将尝试将对象转换为字符串表示形式。例如,
trace
应该如何处理currentTarget
属性?您真的关心IOErrorEvent
的bubbles
属性吗?还是‘构造者’?或者,您可以在循环中进行大量测试,以确定您正在处理的数据类型,并将其一些属性转换为字符串以进行跟踪,但最终您仍然需要使用调试器深入检查对象。
I suggest you find the named properties you want to trace and trace those specifically. Properties that would be useful are
errorId
,text
andtype
. PossiblyeventPhase
as well.As your code stands, you will be trying to convert objects to string representations. What is
trace
supposed to do with thecurrentTarget
property, for example? And do you really care about thebubbles
property ofIOErrorEvent
? 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.