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?

simplfuzz
  • 12,479
  • 24
  • 84
  • 137

2 Answers2

2

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
  • 760
  • 9
  • 19
  • 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'." – simplfuzz Sep 14 '10 at 13:57
  • They cannot coexist on the compiler level, but can be mixed [using namespaces](http://stackoverflow.com/questions/2268276/what-are-the-key-differences-between-javascript-and-actionscript-3/12022657#12022657). – Paul Sweatte Aug 29 '12 at 21:04
0

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

simplfuzz
  • 12,479
  • 24
  • 84
  • 137