views:

55

answers:

2

Assume I have the following class:

class Example
{
    function set something(value:String):void
    {
        trace("set something");
    }

    function doSomething():void
    {
        trace("something");
    }
}

I can access the functions as objects like this:

var example:Example = new Example();
var asdf:Function = example.doSomething;
// this also works - example["doSomething"];

asdf(); // this trace: "something"

You do this all the time with events, for example. So, my big question is: Is there any way to get a handle on the setter? Is there some crazy function on Object or somewhere that I don't know about (please say yes :)

I want something like the following

var example:Example = new Example();

// the following won't work, because example.something is a string
var asdf:Function = example.something; 
asdf("a value"); // this trace: "something"
+1  A: 

The statement var asdf:Function = example.something; won't work because compiler treats example.something as a getter and returns string (or throws a write-only error if the getter is not implemented).

But since something is a property, you can do something like:

example["something"] = "a value"; //will trace 'set something'
//or
var property:String = "something";
example[property] = "some value"; //will trace 'set something'
Amarghosh
Yeah, I know, but I want a handle on the function that DOES that. I need to pass it to another class to be called later. You know how you pass function reference to addEventListener so they can be called when the event fires? Like that.
Sean Clark Hess
A: 
bhups