Re: [flexcoders] Dynamic class creation?

2007-10-22 Thread Ian Thomas
Alex - again, thanks. Please see the other thread for a much fuller
explanation.

Cheers,
  Ian

On 10/22/07, Alex Harui <[EMAIL PROTECTED]> wrote:
>
>I repeat: the recommended practice is to use a custom itemRenderer.
>
>
>


RE: [flexcoders] Dynamic class creation?

2007-10-22 Thread Alex Harui
I repeat: the recommended practice is to use a custom itemRenderer.

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Daniel Freiman
Sent: Monday, October 22, 2007 11:13 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Dynamic class creation?

 

Fill ClassFactory work?

http://livedocs.adobe.com/flex/201/langref/mx/core/ClassFactory.html
<http://livedocs.adobe.com/flex/201/langref/mx/core/ClassFactory.html> 

- Dan Freiman

On 10/22/07, Ian Thomas <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> wrote:

Hi Christophe,
   Unfortunately not, but thanks.

   To explain, I'll copy a response email that I just posted to
Flash_tiger:

-

I know of getDefinitionByName, but that won't work for me as I'm not
returning back different class definitions - I'm returning the _same_
class definition each time, but want to parameterise it. 

As to why I'm doing this / what I'm hoping to achieve...

I'm writing a framework that integrates with the Flex components but
which is agnostic about where its assets come from. I have (for example)
a BitmapData object - never mind how I got it - and want to be able to
transform it into a BitmapAsset class to pass to (say) a TileList. 

To do that I need to be able to pass a Class rather than an instance - a
descendant of BitmapAsset.

I can't pass new BitmapAsset(bitmapData), because that's an instance,
not a class. I can't pass just BitmapAsset, because it doesn't have the
relevant bitmapData and has no way of getting it. I need to pass some
sort of dynamic class or class function which can have new X() called on
it and is parameterised with the appropriate bitmapData. 

Does that make any sense?



Thanks,
Ian

On 10/22/07, Christophe Herreman < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:

Hi Ian,

maybe this will solve your problem (if I understood correctly):
var clazz:Class = getDefinitionByName("com.domain.MyClass") as Class;

http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#getDef
initionByName()
<http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#getDe
finitionByName%28%29> 

regards,
Christophe

 

 



Re: [flexcoders] Dynamic class creation?

2007-10-22 Thread Ian Thomas
Dan,
   Thanks for that; I don't think so (I'd already looked at it). As far as I
can see it's only useful for things expecting a ClassFactory, not a Class.

Cheers,
   Ian

On 10/22/07, Daniel Freiman <[EMAIL PROTECTED]> wrote:
>
>   Fill ClassFactory work?
>
> http://livedocs.adobe.com/flex/201/langref/mx/core/ClassFactory.html
>
> - Dan Freiman
>
>


Re: [flexcoders] Dynamic class creation?

2007-10-22 Thread Daniel Freiman
Fill ClassFactory work?

http://livedocs.adobe.com/flex/201/langref/mx/core/ClassFactory.html

- Dan Freiman

On 10/22/07, Ian Thomas <[EMAIL PROTECTED]> wrote:
>
>   Hi Christophe,
>Unfortunately not, but thanks.
>
>To explain, I'll copy a response email that I just posted to
> Flash_tiger:
>
> -
>
> I know of getDefinitionByName, but that won't work for me as I'm not
> returning back different class definitions - I'm returning the _same_ class
> definition each time, but want to parameterise it.
>
> As to why I'm doing this / what I'm hoping to achieve...
>
> I'm writing a framework that integrates with the Flex components but which
> is agnostic about where its assets come from. I have (for example) a
> BitmapData object - never mind how I got it - and want to be able to
> transform it into a BitmapAsset class to pass to (say) a TileList.
>
> To do that I need to be able to pass a Class rather than an instance - a
> descendant of BitmapAsset.
>
> I can't pass new BitmapAsset(bitmapData), because that's an instance, not
> a class. I can't pass just BitmapAsset, because it doesn't have the relevant
> bitmapData and has no way of getting it. I need to pass some sort of dynamic
> class or class function which can have new X() called on it and is
> parameterised with the appropriate bitmapData.
>
> Does that make any sense?
>
> 
>
> Thanks,
> Ian
>
> On 10/22/07, Christophe Herreman < [EMAIL PROTECTED]> wrote:
> >
> >   Hi Ian,
> >
> > maybe this will solve your problem (if I understood correctly):
> > var clazz:Class = getDefinitionByName("com.domain.MyClass") as Class;
> >
> >
> > http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#getDefinitionByName()
> >
> > regards,
> > Christophe
> >
>  
>


Re: [flexcoders] Dynamic class creation?

2007-10-22 Thread Ian Thomas
Hi Christophe,
   Unfortunately not, but thanks.

   To explain, I'll copy a response email that I just posted to Flash_tiger:

-

I know of getDefinitionByName, but that won't work for me as I'm not
returning back different class definitions - I'm returning the _same_ class
definition each time, but want to parameterise it.

As to why I'm doing this / what I'm hoping to achieve...

I'm writing a framework that integrates with the Flex components but which
is agnostic about where its assets come from. I have (for example) a
BitmapData object - never mind how I got it - and want to be able to
transform it into a BitmapAsset class to pass to (say) a TileList.

To do that I need to be able to pass a Class rather than an instance - a
descendant of BitmapAsset.

I can't pass new BitmapAsset(bitmapData), because that's an instance, not a
class. I can't pass just BitmapAsset, because it doesn't have the relevant
bitmapData and has no way of getting it. I need to pass some sort of dynamic
class or class function which can have new X() called on it and is
parameterised with the appropriate bitmapData.

Does that make any sense?



Thanks,
Ian

On 10/22/07, Christophe Herreman <[EMAIL PROTECTED]> wrote:
>
>   Hi Ian,
>
> maybe this will solve your problem (if I understood correctly):
> var clazz:Class = getDefinitionByName("com.domain.MyClass") as Class;
>
>
> http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#getDefinitionByName()
>
> regards,
> Christophe
>


Re: [flexcoders] Dynamic class creation?

2007-10-22 Thread Christophe Herreman
Hi Ian,

maybe this will solve your problem (if I understood correctly):
var clazz:Class = getDefinitionByName("com.domain.MyClass") as Class;

http://livedocs.adobe.com/flex/2/langref/flash/utils/package.html#getDefinitionByName()

regards,
Christophe

2007/10/22, Ian Thomas <[EMAIL PROTECTED]>:
>
>   Hi all,
>
>   Got a bit of a tricky problem here that I'm banging my head against...
>
>   If you assume I have some function that returns a Class object - for
> example:
>
>   getAssetClass(id:String):Class
>
>   This returns a Class object which, at some future time, will be called
> with new SomeClass() to construct an instance of an object.
>
>   Let's assume that the body of the function looks something like this:
>
>   function getAssetClass(id:String):Class
>   {
>  return GenericAssetClass;
>   }
>
>   However, the actual behaviour I need changes depending on the value of
> 'id'. Effectively what I want to happen is for the returned class to
> be parameterised in some way - so that when new SomeClass() is called it
> evaluates to new GenericAssetClass(id).
>
>   In AS2, this was possible because constructors were just functions. I
> could happily say:
>
>   function getAssetClass(id:String):Function
>   {
>  return function():Object {return new GenericAssetClass(id);}
>   }
>
>  However, in AS3 this won't work, as Class is quite a different thing from
> Function.
>
>  Changing GenericAssetClass.prototype.constructor doesn't help, as it's
> static and applies to all instances of GenericAssetClass.
>
>   Doing something like this:
>
>   function getAssetClass(id:String):Class
>   {
>  GenericAssetClass.id=id;
>  return GenericAssetClass;
>   }
>
>  class GenericAssetClass
>  {
>public static id:String;
>public function GenericAssetClass()
>{
>   // Do something that depends on 'id'
>}
> }
>
> won't help either, because as soon as you change the static
> GenericAssetClass.id, that change applies to all the constructors you've
> handed out.
>
> I could do something like this:
>
>   function getAssetClass(id:String):Class
>   {
>  if (id=="id1")
>  return GenericAssetClass1;
>  else if (id=="id2")
> return GenericAssetClass2;
> // etc. as required
>   }
>
> but the trouble is that there is only one, parameterised GenericAssetClass
> and I can't define all the options up front - it truly is dynamic.
>
> *sigh*
>
> I've a feeling this ought to be possible, I just can't for the life of me
> think how. Is there any way I can hook into the new Class() call somewhere?
> Or uniquely identify each reference to GenericAssetClass that I've handed
> out, so that I can use a lookup table during the construction phase?
>
> Thanks in advance,
> Ian
>  
>



-- 
Christophe Herreman
http://www.herrodius.com


[flexcoders] Dynamic class creation?

2007-10-22 Thread Ian Thomas
Hi all,

  Got a bit of a tricky problem here that I'm banging my head against...

  If you assume I have some function that returns a Class object - for
example:

  getAssetClass(id:String):Class

  This returns a Class object which, at some future time, will be called
with new SomeClass() to construct an instance of an object.

  Let's assume that the body of the function looks something like this:

  function getAssetClass(id:String):Class
  {
 return GenericAssetClass;
  }

  However, the actual behaviour I need changes depending on the value of
'id'. Effectively what I want to happen is for the returned class to
be parameterised in some way - so that when new SomeClass() is called it
evaluates to new GenericAssetClass(id).

  In AS2, this was possible because constructors were just functions. I
could happily say:

  function getAssetClass(id:String):Function
  {
 return function():Object {return new GenericAssetClass(id);}
  }

 However, in AS3 this won't work, as Class is quite a different thing from
Function.

 Changing GenericAssetClass.prototype.constructor doesn't help, as it's
static and applies to all instances of GenericAssetClass.

  Doing something like this:

  function getAssetClass(id:String):Class
  {
 GenericAssetClass.id=id;
 return GenericAssetClass;
  }

 class GenericAssetClass
 {
   public static id:String;
   public function GenericAssetClass()
   {
  // Do something that depends on 'id'
   }
}

won't help either, because as soon as you change the static
GenericAssetClass.id, that change applies to all the constructors you've
handed out.

I could do something like this:

  function getAssetClass(id:String):Class
  {
 if (id=="id1")
 return GenericAssetClass1;
 else if (id=="id2")
return GenericAssetClass2;
// etc. as required
  }

but the trouble is that there is only one, parameterised GenericAssetClass
and I can't define all the options up front - it truly is dynamic.

*sigh*

I've a feeling this ought to be possible, I just can't for the life of me
think how. Is there any way I can hook into the new Class() call somewhere?
Or uniquely identify each reference to GenericAssetClass that I've handed
out, so that I can use a lookup table during the construction phase?

Thanks in advance,
Ian