views:

488

answers:

1

How does one get a reference the the getter and setter functions in actionscript 3?

if a method is defined on the calls, e.g.

public function blah():String { ...}

I can get a reference to it by just saying blah or this.blah

How do get a reference to

public function get blah2():String {}
public function set blah2(b:String):void {}

Thanks!

+1  A: 

Original response:

Unfortunately, you will not be able to store references to those as functions. The getter and setter methods are actually built around the idea that you shouldn't be able to and they therefore function as a property.

Is there a reason that you need to reference the functions specifically?


The comment I'm responding to:

I want to dynamically add external interface methods based on custom metadata tags, e.g. [External]. I was able to do this for the regular methods, but I'm trying to extend this to getter/setters as well. To do this, I need to get a reference to the function dynamically, so I can execute it with the right args using the apply function.

I think you're better off using a multi-step approach in that case. Since getters and setters function as a property and not a method, it would make sense to test to see if it is a property and then simply assign it a value directly. Would you be able to use this:

if( foo.blah2 is Function )
{
    foo.blah2.apply( foo, arr );
}
else
{
    foo.blah2 = arr[ 0 ];
}
Christopher W. Allen-Poole
I want to dynamically add external interface methods based on custom metadata tags, e.g. [External]. I was able to do this for the regular methods, but I'm trying to extend this to getter/setters as well. To do this, I need to get a reference to the function dynamically, so I can execute it with the right args using the apply function.
xyc