Thanks Hans

-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Hans Wichman
Sent: woensdag 29 juli 2009 9:55
To: Flash Coders List
Subject: Re: [Flashcoders] dynamically capture and display the name of the
currently executing function in the Output panel

Yep only in debug player.
Annoying as this was perfectly possible in as 2 (and easy as well). No good
way in as3 though.

Here is one method beside throwing an error and parsing the stack, but it
has to be improved, just show the basic idea (which is kinda the same as in
as2):

  private var d:Dictionary = new Dictionary();

  public function TestOne():void
  {
   var methodNames:Array = getNonstaticAccessors(TestOne);
   for (var i:Number = 0; i < methodNames.length; i++ ) {
    d[this[methodNames[i]]] = methodNames[i];
   }

   init();
  }

  public static function getNonstaticAccessors(classOfInterest:Class):Array
{
   var xmlDescriptionOfClass:XML = describeType(classOfInterest);
   var nonstaticAccessorsXML:XMLList = xmlDescriptionOfClass.factory.method;
   var accessors:Array = [];
   for each (var accessorXML:XML in nonstaticAccessorsXML) {
    accessors.push(accessorx...@name);
   }
   return accessors;
  }

    public function init(e:Event = null):void
  {
  trace (d[arguments.callee]);
}

Only works for public methods though, private methods have to be registered
explicitly.

I think that a utility to parse the bytecode and add this information on the
fly should be possible though:)

regards,
JC



On Tue, Jul 28, 2009 at 11:27 PM, Steve Mathews <happy...@gmail.com> wrote:

> There is a way to this as a hack. No good way though.
> The hack way is to do a try catch, throw an error in the try and parse the
> error message in the catch. Only works with the debug player I believe.
>
>
> On Tue, Jul 28, 2009 at 11:51 AM, Cor <c...@chello.nl> wrote:
>
> > Question: Is there a simple way to dynamically capture and display the
> name
> > of the currently executing function in the Output panel?
> >
> > Sample function:
> >
> > function doStuff ():void {
> > trace ("Function: doStuff()" );
> > //run doStuff code...
> > }
> >
> > Without hardcoding the name of the function in the trace statement shown
> > above, can I somehow display the function name dynamically when it runs?
> > I've never seen this done but thought I'd ask anyway
> >
> > TIA
> > Cor
> > _______________________________________________
> > Flashcoders mailing list
> > Flashcoders@chattyfig.figleaf.com
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to