views:

59

answers:

2

Basically, I want to modify the constructor of the Object
class. Since every class extends Object, I hope whenever any
object of any class is instantiated, the modified function will
be called.

So I did this :

 Object.prototype.constructor = function (){
            trace("it was called;");
        };

and put a breakpoint on the trace statement.

But it didn't stop there.
The trace statement did not get executed also.

Any solutions/suggestions?

A: 

In which context are you coding? If you're using the Flex Compiler MXMLC (default, if you're in FlashBuilder), than you could add the compiler option -es. This should make AS3 feel more like AS2 and JS and support the prototype chain inheritance.

-compiler.es alias -es

"use the ECMAScript edition 3 prototype based object model to allow dynamic overriding of prototype properties. In the prototype based object model built-in functions are implemented as dynamic properties of prototype objects. (advanced)"

I don't know, if this plays well with all the extensions Adobe added to the ECMA Script standard, like packages, namespaces and classes. But you could give it a try.

matths
In Flex Builder when I added the compiler option -es, I got this message : "Invalid -as3 and -es combination. -as3=true and -es=true. Either one of them can be 'true'."
dta
A: 

I don't think it's possible in AS-3, but it was in AS-2.

dta