Did you have a compilation error or a runtime error? It shouldn't have
compiled as written; it would be
service[this.method](params)
not
serivce.[this.method](params)
If you got a runtime error, what did it say?
- Gordon
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Kevin
Sent: Tuesday, March 13, 2007 6:45 PM
To: [email protected]
Subject: Re: [flexcoders] Dynamic Instance of Class & Data Typing
hmm... is there a reason that this would not work on a method that is
added dynamically (in the RemoteObjectClass)? Specifically, here is
what I am trying to accomplish.
private var service:RemoteObject;
public var method:String;
this.service =
ServiceLocator.getInstance().getRemoteObject("addUsersService");
method = "addUser";
var call : Object = service.[this.method]( params );
Thanks,
- Kevin
On Mar 13, 2007, at 8:17 PM, Gordon Smith wrote:
newInstance[someMethodName](someParam)
For example, myCanvas["addChild"](new Button())
- Gordon
________________________________
From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Kevin
Sent: Tuesday, March 13, 2007 5:06 PM
To: [email protected]
Subject: Re: [flexcoders] Dynamic Instance of Class & Data
Typing
by the same token how would I call a method dynamically.
newClass[someMethodName](someParam);
I tried the above with no luck.
thanks, Kevin
On Mar 13, 2007, at 7:19 PM, Gordon Smith wrote:
Yes, assuming that myFavoriteClass is actually linked
into your app. You can use the getDefinitionByName() to look up a class
by name, and the 'new' operator to create an instance of it. I think the
code would be
import flash.utils.getDefinitionByName;
function instantiateClass(className:String):Object
{
var myClass:Class =
Class(getDefinitionByName(className));
return new myClass();
}
- Gordon
________________________________
From: [email protected] [mailto:flexcoders
<mailto:flexcoders> @yahoogroups.com] On Behalf Of Kevin
Sent: Tuesday, March 13, 2007 2:44 PM
To: [email protected]
Subject: [flexcoders] Dynamic Instance of Class & Data
Typing
Is there a way to create new instances of a class
dynamically at
runtime:
var someClass = "myFavoriteClass";
function instantiateClass(someClass){
var event: [someClass] = new [someClass] ();
}
Thanks,
Kevin