Is there a way to convert an expression in AS3 to a string?
I’m making a very small scale profiler for my Flash AS3 files to find the bottlenecks and here’s the current syntax (which is tedious):
PerformanceProfiler.start("updatePlayer");
updatePlayer(map, enemies);
PerformanceProfiler.stop();
I eventually call PerformanceProfiler.show() to get the results from trace calls later on.
Internally, the PerformanceProfiler keeps a dictionary linked by the names of the functions, such as "updatePlayer", to a list of the total milliseconds passed on it.
The show function only lists the function names along with the total time spent on each.
For my needs, this does the trick.
What I’d like, however, is to avoid the whole "updatePlayer" thing, because it’s repetitive. In fact, I’d like to get rid of the start and stop calls completely.
My idea was to call it with some sort of anonymous function, something along the lines of (sorry, I’m not sure about the exact syntax of that feature):
PerformanceProfiler.profile( { updatePlayer(map, enemies); } );
And would only display the results this way:
{ updatePlayer(map, enemies); } – 1202
{ updateEnemies(map, player); } – 5126
…
So, is there a way to get the content of an anonymous method as a string? This would be fantastic. Though, if you have a simpler solution to my problem I would truly appreciate, since we’re getting frame rate drops that we just can’t spot right now, and don’t want to waste time optimizing what could simply be taking 1% of the processing time.
In summary, what I want is:
{ updatePlayer(map, enemies); } converted to "{ updatePlayer(map, enemies); }" in AS3.
Thank you very much for your precious time.
I dont think that there is simple way to do that and know which functions was called without profiler.
But You can create function that will read Namespace.Class.Function names and check parameters using ‘Error’ and ‘arguments’ :