Question :
Is it possible to add behavior to a non-dynamic ActionScript 3 class without inheriting the class?,
Answer :
What I’d like to do is something like the following:
FooClass.prototype.method = function():String { return "Something"; } var foo:FooClass = new FooClass(); foo.method();
Which is to say, I’d like to extend a generated class with a single method, not via inheritance but via the prototype.
The class is generated from a WSDL, it’s not a dynamic class, and I don’t want to touch the generated code because it will be overwritten anyway.
Long story short, I’d like to have the moral equivalent of C# 3:s Extension Methods for AS3.
Edit: I accepted aib’s answer, because it fits what I was asking best — although upon further reflection it doesn’t really solve my problem, but that’s my fault for asking the wrong question. 🙂 Also, upmods for the good suggestions.
,
Yes, such a thing is possible.
In fact, your example is very close to the solution.
Try
foo["method"]();
instead of
foo.method();
That’s the answer Is it possible to add behavior to a non-dynamic ActionScript 3 class without inheriting the class?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
Disclaimer :
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you