[flexcoders] Stump the Flex Nerd: Getting reference to the set method of a property

2008-07-09 Thread Charlie Hubbard
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


Re: [flexcoders] Stump the Flex Nerd: Getting reference to the set method of a property

2008-07-09 Thread Daniel Gold
What are you attempting to do with the reference to the setter? Maybe
there's some other workaround since I haven't seen a way to get a reference
to it, but also haven't really found a need to.

On Wed, Jul 9, 2008 at 2:43 PM, Charlie Hubbard [EMAIL PROTECTED]
wrote:


 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


  



RE: [flexcoders] Stump the Flex Nerd: Getting reference to the set method of a property

2008-07-09 Thread Gordon Smith
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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Charlie Hubbard
Sent: Wednesday, July 09, 2008 12:44 PM
To: flexcoders@yahoogroups.com
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



 



Re: [flexcoders] Stump the Flex Nerd: Getting reference to the set method of a property

2008-07-09 Thread Charlie Hubbard
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:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Charlie Hubbard
 *Sent:* Wednesday, July 09, 2008 12:44 PM
 *To:* flexcoders@yahoogroups.com
 *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





RE: [flexcoders] Stump the Flex Nerd: Getting reference to the set method of a property

2008-07-09 Thread Gordon Smith
But do you really need a setter reference? You can set a property by
name with code like

 

this[users] = result as ArrayCollection;

 

Gordon Smith

Adobe Flex SDK Team

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Charlie Hubbard
Sent: Wednesday, July 09, 2008 2:03 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Stump the Flex Nerd: Getting reference to the
set method of a property

 

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]
mailto:[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: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com
[mailto:flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com ]
On Behalf Of Charlie Hubbard
Sent: Wednesday, July 09, 2008 12:44 PM
To: flexcoders@yahoogroups.com mailto:flexcoders@yahoogroups.com 
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