# Passing variable values between functions

**URL:** <https://forum.kirupa.com/t/passing-variable-values-between-functions/298341>\
**Category:** Uncategorized\
**Created:** [October 16, 2009, 6:24pm UTC](https://forum.kirupa.com/t/passing-variable-values-between-functions/298341 "2009-10-16T18:24:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navarone](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Navarone](https://forum.kirupa.com/u/Navarone)\
**Post date:** [October 16, 2009, 6:24pm UTC](https://forum.kirupa.com/t/passing-variable-values-between-functions/298341/1 "2009-10-16T18:24:06Z")

</div>

How do you pass variable values between functions where the addEventListener is in the first function? I am trying to get the color value passed into my event handler. This is driving me buggy.

```auto

// Create the xmlLoaded function 
function xmlLoaded(event:Event):void {
    myXML = XMLList(myLoader.data);
    var a:int=1;
    var b:int=1;
    // Run the "for each" loop to iterate through all of the menu items listed in the external XML file
    for each (var ListItem:XML in myXML..ListItem) {
        var listColor:String = ListItem.itemColor.toString();
        var listLabel:String = ListItem.itemLabel.toString();
        //trace(xt);
        var rect:MovieClip = new MovieClip();
        var color:Number = Number("0x"+listColor);
        rect.graphics.lineStyle(1, 0x000000);
        rect.graphics.beginFill(color);
        rect.graphics.drawRect(10,10,w,h);
        rect.graphics.endFill();
        rect.x = xt;
        rect.y = yt;
        // This all pertains to the text fields that give our boxes their labels, alter values to your liking
        var myText1:TextField = new TextField();
        myText1.text = listLabel;
        myText1.autoSize = TextFieldAutoSize.LEFT;
        //set location of text field.
        myText1.x = xt+10;
        myText1.y = yt+47;

        //add cell 
        addChild(rect);
        //add text of cell OVER the cell
        addChild(myText1);

        xt = xt+w+space;//set the spacing horizontal
        b=b+1;//next column
        //then changes must be done: prepare for next row
        if (b>j) {
            b=1;
            yt = yt+h+space;//set the spacing vertically
            xt = 0;
        }
        //add mouseEvents for squares
        rect.addEventListener(MouseEvent.CLICK, getColorHandler);
        rect.buttonMode = true;
    }
}

function getColorHandler(event:MouseEvent):void {
    trace(event.currentTarget.transform.colorTransform.color.toString(16));
    var ct:ColorTransform = floorTile.transform.colorTransform;
    ct.color = uint("0x" +event.currentTarget.transform.colorTransform.color.toString(16));
    floorTile.transform.colorTransform = ct;
}

```
