[flexcoders] Re: Set attributes and methods of dynamically added controls
Amy, I got the results I wanted prior to my post with states, but the code is extremely unwieldy and limiting. I'll check out the repeater and post my results back here. Sherm --- In flexcoders@yahoogroups.com, Amy [EMAIL PROTECTED] wrote: --- In flexcoders@yahoogroups.com, daddyo_buckeye projects@ wrote: I was just experimenting with using the 'for' loop to add them dynamically just to see how it's done. I'm pulling the number of colorpickers needed from an XML file, and I need them to run a function to color specific items from that XML file. Then you're definitely better off using either a Repeater or a List Based control. HTH; Amy
[flexcoders] Re: Set attributes and methods of dynamically added controls
--- In flexcoders@yahoogroups.com, daddyo_buckeye [EMAIL PROTECTED] wrote: I'm trying to add a number of colorpickers and textareas to my app dynamically. Each item needs a separate id, and the colorpickers need to call an open() and change() method and pass the textarea id as a parameter along with the event. I'm a little baffled on how to set the methods, but my ids are setting successfully. Here's my code: public function addPicker():void { var i:int; for (i = 0; i 5; i++){ var ssPicker:ColorPicker = new ColorPicker(); var ssTextArea:TextArea = new TextArea(); var ssVBox:VBox = new VBox(); ssPicker.id = cp+i; //note: following two lines don't work. ssPicker.open = openEvt(event,descriptBox+i); ssPicker.change = changeColor(event,descriptBox+i); ssTextArea.id = descriptBox+i; ssTextArea.width = 125; ssTextArea.height = 22; ssTextArea.text = Select Color; myVBox.addChild(ssVBox); ssVBox.addChild(ssPicker); ssVBox.addChild(ssTextArea); } } Setting the id like that won't let you reference it later by ID. Also, you're trying to use the MXML way of assigning event listeners in AS. Try something like this private var cp:Array=new Array(); for (i=0;i5;i++){ ssPicker = new ColorPicker(); cp.push(ssPicker); //you'll need to look at event.currentTarget to see which picker it is ssPicker.addEventListener(open, yourFunction); } You may find that you're better off using a data source that a List control is bound to for this. When the color pickers change the data source, the descriptBoxes, which would be itemRenderers for some other list based control, can automatically pick up the change. HTH; Amy
[flexcoders] Re: Set attributes and methods of dynamically added controls
I was just experimenting with using the 'for' loop to add them dynamically just to see how it's done. I'm pulling the number of colorpickers needed from an XML file, and I need them to run a function to color specific items from that XML file. Sherm --- In flexcoders@yahoogroups.com, Amy [EMAIL PROTECTED] wrote: Setting the id like that won't let you reference it later by ID. Also, you're trying to use the MXML way of assigning event listeners in AS. Try something like this private var cp:Array=new Array(); for (i=0;i5;i++){ ssPicker = new ColorPicker(); cp.push(ssPicker); //you'll need to look at event.currentTarget to see which picker it is ssPicker.addEventListener(open, yourFunction); } You may find that you're better off using a data source that a List control is bound to for this. When the color pickers change the data source, the descriptBoxes, which would be itemRenderers for some other list based control, can automatically pick up the change. HTH; Amy
[flexcoders] Re: Set attributes and methods of dynamically added controls
--- In flexcoders@yahoogroups.com, daddyo_buckeye [EMAIL PROTECTED] wrote: I was just experimenting with using the 'for' loop to add them dynamically just to see how it's done. I'm pulling the number of colorpickers needed from an XML file, and I need them to run a function to color specific items from that XML file. Then you're definitely better off using either a Repeater or a List Based control. HTH; Amy