--- 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;i<5;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

Reply via email to