views:

75

answers:

1

I'm looking for the equivalent of Python decorators / Lisp macros / Java annotations (yes, I know that these are not necessarily equivalent themselves) in Actionscript. Tools that provide similar features would also be great (I'm using the Flex Builder plugin for Eclipse on Linux).

I'm writing a Flex application and here's what I want to accomplish:

I have encapsulated various sets of remote functionality in separate classes (this is sometimes called "Messaging Gateways" or "Remote Proxies"), where each method mirrors a method on the server, like so:

class UserManagementService extends MyHttpService {
  //...
  private final _urlBase:String = "http://example.com/services/users"
  //...

  public function usrGet(ix:int):User
  {
     url = urlBase + "/get";
     mp:Dictionary = new Dictionary();
     mp["ix"] = ix;
     result:User = this._service.varSend(url, this.sEncodeParams(mp), Class("User"));
     return result;
  }
  //...
}

Since I have the parameters and the return type of the remote function already in the function declaration, it would be nice to just add the URL suffix, like this (Python-inspired pseudocode):

@remotify("/get")
public function usrGet(ix:int):User { }

Now, wouldn't that be neat? ;-)

+6  A: 

You can add what is called "metadata" in ActionScript like so:

[Remotify(prop="value")]

More information is here:

http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=11907

cliff.meyers
Cool, I wasn't aware that these were actually customizable. I'll see if that accomplishes what I want.
Hanno Fietz
Yep, you just need to add a special compiler argument so that the information is available at runtime and then use describeType() to retrieve it. The article I linked is super straightforward. Good luck. :)
cliff.meyers