# Can I determine the MouseEvent that was fired?

**URL:** <https://forum.kirupa.com/t/can-i-determine-the-mouseevent-that-was-fired/288957>\
**Category:** flash\
**Created:** [May 24, 2009, 12:59am UTC](https://forum.kirupa.com/t/can-i-determine-the-mouseevent-that-was-fired/288957 "2009-05-24T00:59:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spykes](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Spykes](https://forum.kirupa.com/u/Spykes)\
**Post date:** [May 24, 2009, 12:59am UTC](https://forum.kirupa.com/t/can-i-determine-the-mouseevent-that-was-fired/288957/1 "2009-05-24T00:59:26Z")

</div>

So I have a button that I have attached 2 EventListeners to. It is listening for a MOUSE\_OVER and a MOUSE\_OUT.

```php
ECM_button.addEventListener(MouseEvent.MOUSE_OVER, RollOverECM);
ECM_button.addEventListener(MouseEvent.MOUSE_OUT, RollOverECM);

```

As you can see, both events call the same function. In this function, I would like to create a new instance of a library object and then hide it, depending on the mouseEvent that fires:

```php
 var ECMBox:MovieClip = new managerBox();
        addChild(ECMBox);

```

On the MouseOUT, I would then like to remove that from the stage as such:

```php
removeChild(ECMBox);

```

I did it this way instead of firing two seperate functions because the second function has no reference to the object created in the MOUSE\_OVER function and therefore cannot remove it.  
My question is this: Is there a way to determine in the function that is called, what mouse event called it? If I could get that, then I could set up a condition to create and object or hide the object, depending on what event was fired. Something like this:

```php
ECM_button.addEventListener(MouseEvent.MOUSE_OVER, RollOverECM);
ECM_button.addEventListener(MouseEvent.MOUSE_OUT, RollOverECM);

    function RollOverECM(event:MouseEvent):void {
        if (MOUSE_OVER)//unknown code here
             var ECMBox:MovieClip = new managerBox();
             addChild(ECMBox);
             // Do stuff here, populate the object with data, etc...

        else(MOUSE_OUT)//More unknown code
             removeChild(ECMBox);

```

There is a very good chance I am going about this completely wrong and there is a much easier way. Please advise.
