# Passing variable to event listener

**URL:** https://forum.kirupa.com/t/passing-variable-to-event-listener/294641
**Category:** Uncategorized
**Created:** [August 17, 2009, 8:43pm UTC](https://forum.kirupa.com/t/passing-variable-to-event-listener/294641 "2009-08-17T20:43:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tragic](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tragic](https://forum.kirupa.com/u/tragic)
#### Post date: [August 17, 2009, 8:43pm UTC](https://forum.kirupa.com/t/passing-variable-to-event-listener/294641/1 "2009-08-17T20:43:16Z")

</div>

Hi another dumb question I guess but how do you pass a variable to a listener function? Im trying to add bmp when the mouse goes over this class but i keep getting the undefined error.

```auto

package FlashPackage{
    import flash.display.*;
    import flash.events.*;
    import flash.ui.Mouse;

    public class SomeClass extends Sprite{
        public function SomeClass(){
        var img:BitmapData = new BitmapData(20,20,false,0xFF0000FF);
        var bmp:Bitmap = new Bitmap(img);
        bmp.x = 100;
        bmp.y = 100;
        
        addEventListener(Event.ADDED_TO_STAGE, handler);
        }

        function handler(e:Event):void{
            addEventListener(MouseEvent.MOUSE_OVER, MouseOVER);
        }

        function MouseOVER(e:MouseEvent):void{
            addChild(bmp);
        }
    }
}

```
