Well that was a quick answer thanks. Too bad you can't do this :-( I
noticed in my debugger if I drop a breakpoint inside the set property
function it reports the name of the function as "set property" with a
space. I haven't tested if obj["set property"] would really return that
function or not, but I guess not.
I'm trying to save myself extra typing by going "meta" with my framework.
I'm trying to map the results coming back from say a RemoteObject onto a a
model's property inside the object receiving the server's response. It's
really just trying to save myself the extra work of writing a bunch of tiny
little functions that just do a property set. For example:
var token : AsyncToken = parent.getAllUsers( orderBy );
token.addResponder( new AsyncResponder( generateEvent("usersLoaded", "users"
), generateError("usersFailed"), token ) );
return token;
The meat of this example is the generateEvent() and generateError()
methods. These methods simply return a listener function that will generate
the event specified in the first parameter, and in the case of generateEvent
it will assign the results from the server to the property "users". This
allows the model to load the data form the server asynchronously, then when
the results arrive back it fires a domain level event so the Controller can
grab that event and respond to it, or just use simple Bindable on the
property to update the view if it's a simple response.
My work around is the following:
var token : AsyncToken = parent.getAllUsers( orderBy );
token.addResponder( new AsyncResponder( generateEvent("usersLoaded",
function( result : Object ) : void { users = result as ArrayCollection; }),
generateError("usersFailed"), token ) );
return token;
It just saves me from having to inline an anonymous function that sets the
result onto the property. Makes it slightly cleaner. I'll probably
refactor the whole addResponder mess so that it's even less messy, but I
won't be able to reduce the inline function needed to route the result onto
the property.
Charlie
On Wed, Jul 9, 2008 at 4:40 PM, Gordon Smith <[EMAIL PROTECTED]> wrote:
> There is no way in AS3 to get a reference of type Function to a getter
> or setter. What is your use case for needing such a reference?
>
>
>
> Gordon Smith
>
> Adobe Flex SDK Team
>
>
> ------------------------------
>
> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On
> Behalf Of *Charlie Hubbard
> *Sent:* Wednesday, July 09, 2008 12:44 PM
> *To:* [email protected]
> *Subject:* [flexcoders] Stump the Flex Nerd: Getting reference to the set
> method of a property
>
>
>
>
> Ok, I think I've got a pretty difficult question here. I want to the
> setter method given a string containing the name of a property. With normal
> methods I can always do something like obj.myFunction to get a reference to
> that function, then I can invoke that function with a func.call(). However,
> if you do obj.someProperty that calls the get method. I already tried obj[
> propertyName ] which returned null so that's out.
>
> It's almost like you need another language feature. obj->property= and
> obj->property for ( reference to setter and getter of this property).
>
> Charlie
>
>
>