Re: [Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread JOR

How about using the abstract factory design pattern?

public class MyFactory {
  public static function createObject(objType:String):* {
switch (objType) {
  case Foo:
return new Foo();
  case Bar:
return new Bar();
  default:
return new Foo();
  }
}

var myObj:* = MyFactory.createObject(Foo);


James O'Reilly  —  Consultant
Adobe Certified Flash Expert
http://www.jamesor.com
Design • Code • Train



Matt Muller wrote:

Hi, I'm trying to instantiate a new class object from a xml attribute which
is a string, but its not having any of it.
I've tried casting the string to an object and also using this['class_id']
etc but no luck.

Does someone have a solution?

Thanks,

MaTT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread Benny
MaTT, 

See getDefinitionByName() function in flash.utils
It will give you a reference to the class name that is specified by a
string.
You can then use that reference to get an instance of that class.

Of course you must make sure the class is loaded.

Regards,
Benny


-Oorspronkelijk bericht-
Onderwerp: [Flashcoders] AS3 instantiating a new class object from a string
value

Hi, I'm trying to instantiate a new class object from a xml attribute which
is a string, but its not having any of it.
I've tried casting the string to an object and also using this['class_id']
etc but no luck.

Does someone have a solution?


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread Matt Muller

Thanks, I ended up doing this though...

var ClassReference:Class = getDefinitionByName(com.foo.view.playerSkins. +
aTopNavItems[i].classType) as Class;
this[aTopNavItems[i].class_id] = new ClassReference();

cheers, MaTT

On 7/26/07, Jake Prime [EMAIL PROTECTED] wrote:


I'm not sure about the actual code to instantiate, however make sure
that the class you are creating is actually compiled in the first
place. If it is not explicitly mentioned in your code somewhere it
will not be compiled and will not be able to be created at run-time.

jake

On 26/07/07, Matt Muller [EMAIL PROTECTED] wrote:
 Hi, I'm trying to instantiate a new class object from a xml attribute
which
 is a string, but its not having any of it.
 I've tried casting the string to an object and also using
this['class_id']
 etc but no luck.

 Does someone have a solution?

 Thanks,

 MaTT
 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread R�kos Attila

flash.utils package, getDefinitionByName()

  Attila

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
From:Matt Muller [EMAIL PROTECTED]
To:  Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Date:Thursday, July 26, 2007, 1:29:47 PM
Subject: [Flashcoders] AS3 instantiating a new class object from a string value
--===--
Hi, I'm trying to instantiate a new class object from a xml attribute which
is a string, but its not having any of it.
I've tried casting the string to an object and also using this['class_id']
etc but no luck.

Does someone have a solution?

Thanks,

MaTT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread eka

Hello :)

in AS3 to instanciate an object with only this class name (String) you can
use the flash.utils.getDefinitionByName() method :

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getDefinitionByName()

EKA+ :)


2007/7/26, JOR [EMAIL PROTECTED]:


How about using the abstract factory design pattern?

public class MyFactory {
   public static function createObject(objType:String):* {
 switch (objType) {
   case Foo:
 return new Foo();
   case Bar:
 return new Bar();
   default:
 return new Foo();
   }
}

var myObj:* = MyFactory.createObject(Foo);


James O'Reilly  —  Consultant
Adobe Certified Flash Expert
http://www.jamesor.com
Design • Code • Train



Matt Muller wrote:
 Hi, I'm trying to instantiate a new class object from a xml attribute
which
 is a string, but its not having any of it.
 I've tried casting the string to an object and also using
this['class_id']
 etc but no luck.

 Does someone have a solution?

 Thanks,

 MaTT
 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

[Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread Matt Muller

Hi, I'm trying to instantiate a new class object from a xml attribute which
is a string, but its not having any of it.
I've tried casting the string to an object and also using this['class_id']
etc but no luck.

Does someone have a solution?

Thanks,

MaTT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] AS3 instantiating a new class object from a string value

2007-07-26 Thread Jake Prime

I'm not sure about the actual code to instantiate, however make sure
that the class you are creating is actually compiled in the first
place. If it is not explicitly mentioned in your code somewhere it
will not be compiled and will not be able to be created at run-time.

jake

On 26/07/07, Matt Muller [EMAIL PROTECTED] wrote:

Hi, I'm trying to instantiate a new class object from a xml attribute which
is a string, but its not having any of it.
I've tried casting the string to an object and also using this['class_id']
etc but no luck.

Does someone have a solution?

Thanks,

MaTT
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com