views:

326

answers:

1

Is there a line number constant or way to dynamically trace the line number in actionscript?

Does actionscript have the equivalent of

__LINE__

in PHP?

+6  A: 

Hi,

This is not a CONSTANT but this line of code will give you the line number:

trace(">",new Error().getStackTrace().match(/(?<=:)[0-9]*(?=])/g)[0]);

PS: this will only work if the swf is compiled in debug mode

OXMO456
wow, that's cool
jedierikb
Very nice trick!
HanClinto
Thank you guys !!!
OXMO456
Interesting approach. This has got me thinking about the problem in a new way. Thanks. What other useful information do you often pull out of the stack trace? Do you ever use this technique to create conditional breakpoints in the code? For example adding a break point when a very specific parameter has been passed to a function? I suppose in that case one could just put in conditional test for the parameter and wrap a break point inside it.
Gordon Potter
hi !i never use this trick... and i am not sure we can add dynamicly breakpoints in as3... but in order to debug your application, you can still throw an exception...hope that will help you... sorry i am french, my english is very poor... : (
OXMO456