Some great suggestions thanks! ... I guess in essence I simply wanted to extend the inbuilt trace function rather than overriding it ... all I wanted to do was append which class and or method the trace was called from. My immediate need is for debugging someone else's very buggy code that I have just come onto at the end of it's lifecycle .. for future projects, then something like what Hans mentioned might be the way to go.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Francis Turmel Sent: Wednesday, 16 July 2008 7:25 AM To: Flash Coders List Subject: Re: [Flashcoders] Overriding the trace command As everyone else mentioned, I don't think there's a way to override the trace function in as3. However, if you put a public function in the "unnamed" package, your application will be able to reach this function from anywhere, so if you're willing to use something else like log() or debug() as a method name instead of trace(), then you can replicate the trace function's behavior and add your own customizations. I've been using this to route my traces to AirLogger, for example. As a quick demo, this would just route your arguments to the trace function. Just put the following code in a file called debug.as in the root of your classpath. package { public function debug(...args):void { trace.apply(null, args); } } Hope this helps! On Tue, Jul 15, 2008 at 10:08 AM, Juan Pablo Califano < [EMAIL PROTECTED]> wrote: > I'm afraid you can't extend the trace builtin function . Using another > function or logging class and then redirecting the trace to some logger > console or even the trace() function, if at some point you need it, is the > way to go. MTASC handles that trace replacement through a compiler > switch, like a preprocessor macro, making textual substitutions to trace > calls in the AS. > > The thing is that trace function is not compiled into a call to an > actionscript function, but it's embedded directly with its own bytcode in > the swf. That's why you can't change its behaviour from AS code. > > > Cheers > Juan Pablo Califano > > 2008/7/15, Adam Jowett <[EMAIL PROTECTED]>: > > > > Hi all, > > > > > > > > A very quick one, I haven't had to over-ride or extend built in classes > > since the good old days of prototyping in AS1, specifically this time I > > want > > to extend the built in trace() statement with some conditions etc. Can > this > > be done? or do I need to do my own custom logger such as those out there > at > > the moment? > > > > > > > > Cheers > > > > Adam > > > > _______________________________________________ > > 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