[Flashcoders] AS3 new Class from string

2007-06-18 Thread Patrick Matte|BLITZ
Hey fellows, in AS3 how can I create class instances from a list of classes 
names. Take for example something like this:

import Circle;
import Square;
import Triangle;

var list:Array = new Array(Circle,Square,Triangle);

for(var i=0;ilist.length;i++){
var class = new list[i]();
}
___
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 new Class from string

2007-06-18 Thread elibol

Not sure since eval() is gone.

Try keeping a reference for each class in some object and use it like a hash
map.

import Circle;
import Square;
import Triangle;

var classes:Object {
Circle:Circle
, Square:Square
, Triangle:Triangle
};

var list:Array = new Array(Circle,Square,Triangle);

for(var i=0;ilist.length;i++){
  var cls:Class = classes[list[i]];
  var instance:* = new cls();
}

It would be nice to see a less involved solution though...

On 6/18/07, Patrick Matte|BLITZ [EMAIL PROTECTED] wrote:


Hey fellows, in AS3 how can I create class instances from a list of
classes names. Take for example something like this:

import Circle;
import Square;
import Triangle;

var list:Array = new Array(Circle,Square,Triangle);

for(var i=0;ilist.length;i++){
var class = new list[i]();
}
___
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 new Class from string

2007-06-18 Thread Jim Kremens

Just remove the quotation marks from your array so it looks like this:

var list:Array = new Array(Circle,Square,Triangle);

Assuming your import statements are right, your code will work.

Jim Kremens
___
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 new Class from string

2007-06-18 Thread Jim Kremens

There's also this:

var ClassRef:Object = getDefinitionByName(flash.display::Sprite);
var element:Sprite = new ClassRef();

That allows you to really use a string and not a class reference,
which is what I think you want...

But, as with Flash 8, the class reference must really exist in your
swf somewhere, so
you may as well do what elibol suggested...

Jim Kremens
___
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 new Class from string

2007-06-18 Thread elibol

Actually, I would do it how Jim suggested - using the getDefinitionByName
function. It's that less involved solution I did not know about. Where is
this function documented?

On 6/18/07, Jim Kremens [EMAIL PROTECTED] wrote:


There's also this:

var ClassRef:Object = getDefinitionByName(flash.display::Sprite);
var element:Sprite = new ClassRef();

That allows you to really use a string and not a class reference,
which is what I think you want...

But, as with Flash 8, the class reference must really exist in your
swf somewhere, so
you may as well do what elibol suggested...

Jim Kremens
___
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 new Class from string

2007-06-18 Thread Muzak
flash.utils.getDefinitionByName()

There's some more useful stuff in the flash.utils package.
Have a look in the docs.

Muzak

- Original Message - 
From: Patrick Matte|BLITZ [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Monday, June 18, 2007 10:24 PM
Subject: [Flashcoders] AS3 new Class from string


Hey fellows, in AS3 how can I create class instances from a list of classes 
names. Take for example something like this:

import Circle;
import Square;
import Triangle;

var list:Array = new Array(Circle,Square,Triangle);

for(var i=0;ilist.length;i++){
var class = new list[i]();
}


___
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 new Class from string

2007-06-18 Thread jtgxbass

In AS3 is done like this...

import flash.utils.getDefinitionByName;
var ObClass:Class = getDefinitionByName( fully.qualified.class.name ) as
Class;
var instance = new ObClass();



On 6/18/07, elibol [EMAIL PROTECTED] wrote:


Not sure since eval() is gone.

Try keeping a reference for each class in some object and use it like a
hash
map.

import Circle;
import Square;
import Triangle;

var classes:Object {
Circle:Circle
, Square:Square
, Triangle:Triangle
};

var list:Array = new Array(Circle,Square,Triangle);

for(var i=0;ilist.length;i++){
   var cls:Class = classes[list[i]];
   var instance:* = new cls();
}

It would be nice to see a less involved solution though...

On 6/18/07, Patrick Matte|BLITZ [EMAIL PROTECTED] wrote:

 Hey fellows, in AS3 how can I create class instances from a list of
 classes names. Take for example something like this:

 import Circle;
 import Square;
 import Triangle;

 var list:Array = new Array(Circle,Square,Triangle);

 for(var i=0;ilist.length;i++){
 var class = new list[i]();
 }
 ___
 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 new Class from string

2007-06-18 Thread jtgxbass

Jim:


getDefinitionByName(flash.display::Sprite);



Should read:
getDefinitionByName(flash.display.Sprite);

I think.


On 6/18/07, jtgxbass [EMAIL PROTECTED] wrote:


In AS3 is done like this...

import flash.utils.getDefinitionByName;
var ObClass:Class = getDefinitionByName( fully.qualified.class.name  )
as Class;
var instance = new ObClass();



On 6/18/07, elibol  [EMAIL PROTECTED] wrote:

 Not sure since eval() is gone.

 Try keeping a reference for each class in some object and use it like a
 hash
 map.

 import Circle;
 import Square;
 import Triangle;

 var classes:Object {
 Circle:Circle
 , Square:Square
 , Triangle:Triangle
 };

 var list:Array = new Array(Circle,Square,Triangle);

 for(var i=0;ilist.length;i++){
var cls:Class = classes[list[i]];
var instance:* = new cls();
 }

 It would be nice to see a less involved solution though...

 On 6/18/07, Patrick Matte|BLITZ  [EMAIL PROTECTED] wrote:
 
  Hey fellows, in AS3 how can I create class instances from a list of
  classes names. Take for example something like this:
 
  import Circle;
  import Square;
  import Triangle;
 
  var list:Array = new Array(Circle,Square,Triangle);
 
  for(var i=0;ilist.length ;i++){
  var class = new list[i]();
  }
  ___
  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 new Class from string

2007-06-18 Thread elibol

I see what you mean Jim. Maybe it's best used for classes loaded via swc
libraries.

On 6/18/07, elibol [EMAIL PROTECTED] wrote:


Actually, I would do it how Jim suggested - using the getDefinitionByName
function. It's that less involved solution I did not know about. Where is
this function documented?

On 6/18/07, Jim Kremens [EMAIL PROTECTED] wrote:

 There's also this:

 var ClassRef:Object = getDefinitionByName(flash.display::Sprite);
 var element:Sprite = new ClassRef();

 That allows you to really use a string and not a class reference,
 which is what I think you want...

 But, as with Flash 8, the class reference must really exist in your
 swf somewhere, so
 you may as well do what elibol suggested...

 Jim Kremens
 ___
 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 new Class from string

2007-06-18 Thread Patrick Matte|BLITZ
But using getDefinitionByName, can you find a class that's inside a loaded swf?
Like in this example, Test is a class inside test.swf but I get an Error #1065: 
Variable Test is not defined. But it works fine if I call getDefinitionByName 
from within test.swf

public function GetDefinitionByNameExample() {
var request:URLRequest = new URLRequest(test.swf);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeEvent);
loader.load(request);
}

private function completeEvent(e:Event):void{
trace(completeEvent);
var ClassReference:Class = getDefinitionByName(Test) as Class;
var instance:Object = new ClassReference();
}



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jim Kremens
Sent: Monday, June 18, 2007 1:52 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] AS3 new Class from string

There's also this:

var ClassRef:Object = getDefinitionByName(flash.display::Sprite);
var element:Sprite = new ClassRef();

That allows you to really use a string and not a class reference,
which is what I think you want...

But, as with Flash 8, the class reference must really exist in your
swf somewhere, so
you may as well do what elibol suggested...

Jim Kremens
___
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 new Class from string

2007-06-18 Thread Muzak
Look up: ApplicationDomain.getDefinition()

flash.system.ApplicationDomain
flash.system.LoaderContext.applicationDomain

regards,
Muzak

- Original Message - 
From: Patrick Matte|BLITZ [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Tuesday, June 19, 2007 1:23 AM
Subject: RE: [Flashcoders] AS3 new Class from string


But using getDefinitionByName, can you find a class that's inside a loaded swf?
Like in this example, Test is a class inside test.swf but I get an Error #1065: 
Variable Test is not defined. But it works fine if I 
call getDefinitionByName from within test.swf



___
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 new Class from string

2007-06-18 Thread Patrick Matte|BLITZ
Thanks that's sweet !

BLITZ | Patrick Matte - 310-551-0200 x214

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak
Sent: Monday, June 18, 2007 4:52 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] AS3 new Class from string

Look up: ApplicationDomain.getDefinition()

flash.system.ApplicationDomain
flash.system.LoaderContext.applicationDomain

regards,
Muzak

- Original Message -
From: Patrick Matte|BLITZ [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Tuesday, June 19, 2007 1:23 AM
Subject: RE: [Flashcoders] AS3 new Class from string


But using getDefinitionByName, can you find a class that's inside a loaded swf?
Like in this example, Test is a class inside test.swf but I get an Error #1065: 
Variable Test is not defined. But it works fine if I
call getDefinitionByName from within test.swf



___
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