Re: [Flashcoders] create an object of type defined with a string

2006-06-04 Thread Tyler Wright

If you need an object that already exists to be converted into an instance
of the class you can use the XT Prototype class

Prototype.makeInstanceof(obj, Array);

and using Zimmen's suggestion

Prototype.makeInstanceof(obj, _global[tType]);

good luck! you'll find the class at
http://codext.com/code/9

Tyler

On 6/1/06, Zimmen [EMAIL PROTECTED] wrote:


Yes it is... so you could use

function makeObject(tType){
   return (new _global[tType]())
}
test = makeObject(Array)

as well (this is what the findClass method does eventually. :)

On 6/1/06, Danny Kodicek [EMAIL PROTECTED] wrote:
 Thanks, Zimmen and Ian, that's helpful. I'll probably go with Ian's
 solution, which seems a bit more robust (I've been caught out before by
 clever tricks using eval()...)

 Danny

 - Original Message -
 From: Zimmen [EMAIL PROTECTED]
 To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
 Sent: Thursday, June 01, 2006 5:33 PM
 Subject: Re: [Flashcoders] create an object of type defined with a
string


  This actually works:
 
  function makeObject(tType){
  var tVar = eval(tType)
  return (new tVar())
  }
  test = makeObject(Array)
  test.push(foo)
  test.push(bar)
  trace(test[0])
  trace(test[1])
  trace(test.length)
 
  Output:
 
  foo
  bar
  2
 
  On 6/1/06, Danny Kodicek [EMAIL PROTECTED] wrote:
  I want to have a function makeObject(tType:String) which returns an
  object
  of class tType. So makeObject(Array) should return a new Array
object.
  Any
  good way to do this? I'm sure it's something simple.
 
  And before you ask, yes, there is a reason why I need to do it this
  way...
 
  Danny
 
  ___
  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@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] create an object of type defined with a string

2006-06-01 Thread Ian Thomas

Hi Danny,
mx.utils.ClassFinder.findClass(SomeClass) returns the constructor
function for a class.

e.g.
var className:String = 'String';
var cls:Function = mx.utils.ClassFinder.findClass(className);
var object:Object = new cls();

Hope that helps,
 Ian

On 6/1/06, Danny Kodicek [EMAIL PROTECTED] wrote:

I want to have a function makeObject(tType:String) which returns an object
of class tType. So makeObject(Array) should return a new Array object. Any
good way to do this? I'm sure it's something simple.

And before you ask, yes, there is a reason why I need to do it this way...

Danny

___
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] create an object of type defined with a string

2006-06-01 Thread Zimmen

This actually works:

function makeObject(tType){
var tVar = eval(tType)
return (new tVar())
}
test = makeObject(Array)
test.push(foo)
test.push(bar)
trace(test[0])
trace(test[1])
trace(test.length)

Output:

foo
bar
2

On 6/1/06, Danny Kodicek [EMAIL PROTECTED] wrote:

I want to have a function makeObject(tType:String) which returns an object
of class tType. So makeObject(Array) should return a new Array object. Any
good way to do this? I'm sure it's something simple.

And before you ask, yes, there is a reason why I need to do it this way...

Danny

___
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] create an object of type defined with a string

2006-06-01 Thread Danny Kodicek
Thanks, Zimmen and Ian, that's helpful. I'll probably go with Ian's 
solution, which seems a bit more robust (I've been caught out before by 
clever tricks using eval()...)


Danny

- Original Message - 
From: Zimmen [EMAIL PROTECTED]

To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Thursday, June 01, 2006 5:33 PM
Subject: Re: [Flashcoders] create an object of type defined with a string



This actually works:

function makeObject(tType){
var tVar = eval(tType)
return (new tVar())
}
test = makeObject(Array)
test.push(foo)
test.push(bar)
trace(test[0])
trace(test[1])
trace(test.length)

Output:

foo
bar
2

On 6/1/06, Danny Kodicek [EMAIL PROTECTED] wrote:
I want to have a function makeObject(tType:String) which returns an 
object
of class tType. So makeObject(Array) should return a new Array object. 
Any

good way to do this? I'm sure it's something simple.

And before you ask, yes, there is a reason why I need to do it this 
way...


Danny

___
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] create an object of type defined with a string

2006-06-01 Thread Nick Gerig

just for the record you don't need to use eval:

trace(new [Array]() instanceof Array)


Cheers

Nick


Danny Kodicek wrote:

Thanks, Zimmen and Ian, that's helpful. I'll probably go with Ian's 
solution, which seems a bit more robust (I've been caught out before 
by clever tricks using eval()...)


Danny






___
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] create an object of type defined with a string

2006-06-01 Thread Tom Lee
Danny,

Out of curiosity, why do you need a function that returns an object of a
type passed as a string?  It's a neat idea, but I'm scratching my head as to
where one might apply it.

-tom

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Danny
Kodicek
Sent: Thursday, June 01, 2006 12:51 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] create an object of type defined with a string

Thanks, Zimmen and Ian, that's helpful. I'll probably go with Ian's 
solution, which seems a bit more robust (I've been caught out before by 
clever tricks using eval()...)

Danny

- Original Message - 
From: Zimmen [EMAIL PROTECTED]
To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com
Sent: Thursday, June 01, 2006 5:33 PM
Subject: Re: [Flashcoders] create an object of type defined with a string


 This actually works:

 function makeObject(tType){
 var tVar = eval(tType)
 return (new tVar())
 }
 test = makeObject(Array)
 test.push(foo)
 test.push(bar)
 trace(test[0])
 trace(test[1])
 trace(test.length)

 Output:

 foo
 bar
 2

 On 6/1/06, Danny Kodicek [EMAIL PROTECTED] wrote:
 I want to have a function makeObject(tType:String) which returns an 
 object
 of class tType. So makeObject(Array) should return a new Array object. 
 Any
 good way to do this? I'm sure it's something simple.

 And before you ask, yes, there is a reason why I need to do it this 
 way...

 Danny

 ___
 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@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] create an object of type defined with a string

2006-06-01 Thread Danny Kodicek

 Danny,

 Out of curiosity, why do you need a function that returns an object of a
 type passed as a string?  It's a neat idea, but I'm scratching my head as
to
 where one might apply it.

I've been hitting some memory problems when using Director's newObject()
function, which creates a new object inside an embedded Swf. Because the
object is unnamed, I have no way to destroy it in the Flash movie - it seems
to go somewhere in the global space. So instead, I'm making my own
tempObject function, which creates a new object in an array pTempObjects in
the Flash movie. When I've finished working with it, I run a
clearTempObjects() function to flush them out.

So I have this function:

function tempObject(tName:String) {
 var tObj:Object = new Object of type tName
 pTempObjects.push(tObj)
 return tObj
}

Now Director can call this function, get a new temporary Flash object and
work on it, then tell Flash to do something with the object (eg, setting the
properties of a TextFormat object before applying it to a field), and then
finally clear it out.

More detail than I think you wanted, but since you asked :)

Danny

___
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] create an object of type defined with a string

2006-06-01 Thread Tom Lee
Makes total sense!  Valuable info for the rare occasion I do a
Director/Flash hybrid.  Thanks for indulging me. :)

-tom

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Danny
Kodicek
Sent: Thursday, June 01, 2006 2:26 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] create an object of type defined with a string


 Danny,

 Out of curiosity, why do you need a function that returns an object of a
 type passed as a string?  It's a neat idea, but I'm scratching my head as
to
 where one might apply it.

I've been hitting some memory problems when using Director's newObject()
function, which creates a new object inside an embedded Swf. Because the
object is unnamed, I have no way to destroy it in the Flash movie - it seems
to go somewhere in the global space. So instead, I'm making my own
tempObject function, which creates a new object in an array pTempObjects in
the Flash movie. When I've finished working with it, I run a
clearTempObjects() function to flush them out.

So I have this function:

function tempObject(tName:String) {
 var tObj:Object = new Object of type tName
 pTempObjects.push(tObj)
 return tObj
}

Now Director can call this function, get a new temporary Flash object and
work on it, then tell Flash to do something with the object (eg, setting the
properties of a TextFormat object before applying it to a field), and then
finally clear it out.

More detail than I think you wanted, but since you asked :)

Danny

___
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] create an object of type defined with a string

2006-06-01 Thread Pedro Ruiz de Valdivia Molina
If you were using Flex, I think there is a way to do it: let us know if you use 
Flex.
Regards.

-Mensaje original-
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] nombre de Danny
Kodicek
Enviado el: jueves, 01 de junio de 2006 18:02
Para: Flashcoders mailing list
Asunto: [Flashcoders] create an object of type defined with a string


I want to have a function makeObject(tType:String) which returns an object 
of class tType. So makeObject(Array) should return a new Array object. Any 
good way to do this? I'm sure it's something simple.

And before you ask, yes, there is a reason why I need to do it this way...

Danny 

___
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