Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add behavior to a non-dynamic ActionScript 3 class without inheriting the class?

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.

like image 434
Rytmis Avatar asked Aug 10 '08 15:08

Rytmis


1 Answers

Yes, such a thing is possible.

In fact, your example is very close to the solution.

Try

foo["method"]();

instead of

foo.method();
like image 126
aib Avatar answered Nov 15 '22 06:11

aib