Well, let's be fair.  You can't create new class defs at runtime, and it
would help to have a better definition of the problem so we aren't
taking stabs in the dark.

 

However, to take one last stab, let's assume that Rafael is trying to
have declarative or runtime data-schema mapping to a renderer.  The list
classes allow one field to be mapped via labelField and multiple fields
to be mapped via labelFunction, but if you use labelFunction you lose
the reverse mapping which a custom editor might want.  IOW, if your
labelFunction merges firstName and lastName, and you want an editor to
parse apart what goes back into firstName and what goes back into
lastName, you need to identify those fields to the editor, and if you
want to re-purpose the same editor to work on  some other pair
(managerFirstName, managerLastName), that should be possible as well.

 

A subclass of TextInput might have field1 and field2 properties that are
strings, and an overridden commitProperties that takes the data and
pulls the two fields from it.  It might have an onFocusOut handler that
writes back the parsed string into those two fields.

 

You can just use the standard properties bag on ClassFactory to set
those fields or just set them in the mx:Component declaration

 

<mx:Component>

            <comp:MultiFieldTextInput field1="firstName"
field2="lastName" />

</mx:Component>

 

-Alex

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Josh McDonald
Sent: Thursday, July 24, 2008 7:37 PM
To: [email protected]
Subject: Re: [flexcoders] Re: new Component() ?

 

You can't really do what you want, without creating custom item renderer
components or custom IFactories. You could possibly create one base
component, and pass in a callback function as one of the parameters in
initObject for an InitFactory, but that's a terrible idea for any number
of reasons, chiefly your code will be unreadable and unmaintainable.

Honestly if you'd just tell us what and why you're actually trying to
achieve for the end user (and why you just can't use regular renderer
classes or labelfunctions) then we'd be able to give you alternatives
that make sense for your use case.

-Josh 

On Fri, Jul 25, 2008 at 10:14 AM, Rafael Faria
<[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> >
wrote:

I found this class

package modules.renderers
{
       import mx.core.ClassFactory;

       import org.osflash.thunderbolt.Logger;

       public class InitFactory extends ClassFactory
       {
               private var initObject:Object;

               public function InitFactory(generator:Class,
initObject:Object)
               {
                       super(generator);
                       this.initObject = initObject;
               }

               public override function newInstance():*
               {
                       var result:* = super.newInstance();

                       for(var propertyName:String in initObject)
                       {
                               try
                               {
                                       result[propertyName] =
initObject[propertyName];
                               }catch (e:Error)
                               {
                                       trace(e.message);
                               }
                       }
                       return result;
               }
       }
}


and i'm able to add a new class on the fly doing


dgc.itemRenderer = new InitFactory(TextInput, {text:'Value inside the
text input'});


now i'm struggling to make the textinput, to get values from the
"data" variable coming from the dataProvider. You know, when inside
the itemrender you can use {data.firstname + ' ' + data.lastname}
like: <mx:TextInput text="{data.firstname + ' ' + data.lastname}" />

With the example i gave above, how i would do that?

Raf



Any idea how i would pass this data to the checkbox label





--- In [email protected] <mailto:[email protected]> ,
"Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> You can't add to the class definition of the Canvas at runtime.
> ClassFactory has a properties bag where you can have properties
slapped
> on the new instance, but that's not really a new class definition.
>
>
>
> ________________________________
>
> From: [email protected] <mailto:[email protected]>
[mailto:[email protected] <mailto:[email protected]> ]
On
> Behalf Of Amy
> Sent: Thursday, July 24, 2008 7:36 AM
> To: [email protected] <mailto:[email protected]> 
> Subject: [flexcoders] Re: new Component() ?
>
>
>

> --- In [email protected] <mailto:[email protected]>
<mailto:flexcoders%40yahoogroups.com
<mailto:flexcoders%2540yahoogroups.com> >

> , "Alex Harui" <aharui@> wrote:
> >
> > If you've defined a component via <mx:Component>, the name is
> > auto-generated as Josh says, but it generates an IFactory, so you
> can
> > use the factory to get new instances
> >
> >
> >
> > <mx:List id="myList>
> >
> > <mx:itemRenderer>
> >
> > <mx:Component>
> >
> > <mx:Canvas>
> >
> > ..
> >
> >
> >
> >
> >
> > From AS:
> >
> >
> >
> > myList.itemRenderer.newInstance()
>
> This makes it sound like the equivalent to new Component() in AS
> might be
>
> myRenderer:ClassFactory = new ClassFactory(mx.containers.Canvas);
>
> Presumably from there you can add stuff to myRenderer before using it
> as your "rubber stamp", but I've never personally used ClassFactory
> for anything other than setting global properties on a class I
> created in AS3 or MXML.
>
> Is this a correct interpretation of how AS3 works?
>
> Thanks;
>
> Amy
>



------------------------------------

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
<http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> 

Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo
<http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> ! Groups
Links

   http://groups.yahoo.com/group/flexcoders/
<http://groups.yahoo.com/group/flexcoders/> 


   (Yahoo! ID required)

   mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 






-- 
"Therefore, send not to know For whom the bell tolls. It tolls for
thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>  

 

Reply via email to