views:

725

answers:

4
var alias:String = 'models.User';
registerClassAlias(alias, models.User);

// If I have the alias, then
// I can get the class like this:
var klass:Class = flash.net.getClassByAlias(alias);

// How do I do the reverse
// (get the alias from the class)?
//
// I want to do this, but I can't find a 
// 'getAliasByClass' function.
alias = getAliasByClass(klass);
+1  A: 

Take a look at flash.utils.describeType()

Antti
What would you parse in the describeType() XML to get the [RemoteClass(alias="com.foo.javaClassName")]From this code example it looks like you can get attributes using @. override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void { var desc:XML = describeType(o); var classAlias:String = desc.@alias;//...}
Dougnukem
A: 

getQualifiedClassName should do the trick.

alias = flash.utils.getQualifiedClassName( klass );
// should return: "models::User"

You can pass it a class reference, or an instance of the class, either way.

fenomas
I need the class alias, not the actual AS3 class name.
limscoder
Oh - you mean essentially that you want to query which, if any, alias has been registered to a given class? I don't think you can do that. Even if you could, there could be multiple aliases for a given class, couldn't there? I don't know this definitively though, so I'll leave this as a comment.
fenomas
A: 

As stated above you can call flash.utils.describeType() and use "reflection" on your Actionscript object's class to query attributes, properties, methods of the object.

For example the following code snippet for ObjectCodec.as seems to retrieve the alias attribute by using "@":

override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void
{
  var desc:XML = describeType(o);
  var classAlias:String = desc.@alias;
  //...
}
Dougnukem
A: 

I think you should check out SWFExplorer by Didier Brun (http://www.bytearray.org/?p=175). SWFExplorer lets you retrieve all the linked-classes available in an ActionScript 3 SWF.

Greet Sid

Sidney