Flash AS Event Properties: Possible to trace them with a for loop?
I was wonde开发者_Python百科ring 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!
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.
精彩评论