[flexcoders] Set attributes and methods of dynamically added controls

2008-07-19 Thread daddyo_buckeye
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);
}
}

Any thoughts on how I can accomplish this?



Re: [flexcoders] Set attributes and methods of dynamically added controls

2008-07-19 Thread shaun
daddyo_buckeye 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);
   }
 }
 
 Any thoughts on how I can accomplish this?

As a guess..

ssPicker.open = openEvt;
ssPicker.change = changeColor;

lookup[ssPicker.id] = ssTextArea; //associate picker and text

function openEvt(event:Event){
   var colorPicker:ColorPicker = ColorPicker(event.target);
   var t:TextArea = lookup[colorPicker.id];

   t.text = colorPicker.id;
   ...
}

HTH.
  - shaun



Re: [flexcoders] Set attributes and methods of dynamically added controls

2008-07-19 Thread shaun
shaun wrote:
 daddyo_buckeye wrote:

[snip]

 Any thoughts on how I can accomplish this?
 
 As a guess..
 
 ssPicker.open = openEvt;
 ssPicker.change = changeColor;

Whoops. Scrap that.
As Amy said, it should be using addEventListener..
Getting languages mixed up... :-/

 
 lookup[ssPicker.id] = ssTextArea; //associate picker and text
 
 function openEvt(event:Event){
var colorPicker:ColorPicker = ColorPicker(event.target);

And probably currentTarget rather than target.

- shaun