I also tested label and it works.

So target.label will display the label.

target.id will display the ID.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute">

<mx:Script>

<![CDATA[

private function fillLabel(evt:Event):void

{

myLabel.text=evt.target.label ;

}

]]>

</mx:Script>

<mx:Panel x="320" y="127" width="250" height="200" layout="absolute" 
title="Testing">

<mx:VBox x="79" y="55" height="100%" >

<mx:Label id="myLabel"/>

<mx:Button label="This is a test" id="myButton" click="fillLabel(event)"/>

</mx:VBox>

</mx:Panel>

</mx:Application>

________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lucas Golden
Sent: Monday, September 29, 2008 3:51 PM
To: [email protected]
Subject: [AFFUG Discuss] Event Listeners and Dynamically created Items

Hey folks,

I've got an issue where I'm creating a series of buttons inside of a loop.  I'm 
then creating an Event Listener inside that loop to go along with the button to 
create an onClick event.   Is there anyway I can pass a value or even get the 
name of the button that was clicked inside of the Event Listener?  I've tried  
"this.name<http://this.name>"  but it just gives the application name.

Here's my loop and my event listener:

     for(var m:int = 0; m < optionArray.length; m++)
       {
            var optionHBox:HBox = new HBox();
               var optionImage:Image = new Image();
               var optionButton:Button = new Button();   //button creations
               var optionLabel:Text = new Text();
               optionLabel.width = 100;
               optionLabel.percentHeight = 100;

               optionImage.source = optionArray[m].optionURL;
               optionImage.setStyle("horizontalCenter","0");
               optionImage.addEventListener("click",clickColor);


               optionLabel.htmlText = optionArray[m].label;
               optionButton.toggle = true;

               optionButton.name = "optionButton" + i + m;        //button name
               optionButton.id = "optionButton" + i + m;            // button ID
               optionButton.addEventListener("click",optionClick);


               optionButton.setStyle("horizontalCenter","0");
               optionHBox.addChild(optionButton);
               optionHBox.addChild(optionImage);
               optionHBox.addChild(optionLabel);
               optionHBox.y = newLabel2.y + 30;

            optionHBox.width = 235;
            optionHBox.setStyle("horizontalCenter","0");
            optionHBox.setStyle("horizontalAlign","center");
            optionVBox.addChild(optionHBox);
       }


and here's the event Listener Function:

  private function optionClick(event:Event):void
   {
        Alert.show(this.name<http://this.name>);  //this is just here to try 
and see if I can get a value though.
    }



Thanks for the help!
Luke


-------------------------------------------------------------
To unsubscribe from this list, simply email the list with unsubscribe in the 
subject line

For more info, see http://www.affug.com
Archive @ http://www.mail-archive.com/discussion%40affug.com/
List hosted by FusionLink<http://www.fusionlink.com>
-------------------------------------------------------------



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

To unsubscribe from this list, simply email the list with unsubscribe in the 
subject line



For more info, see http://www.affug.com

Archive @ http://www.mail-archive.com/discussion%40affug.com/

List hosted by http://www.fusionlink.com

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

Reply via email to