# Multiple EventListeners, modulus and rotating cubes... performance issues

**URL:** <https://forum.kirupa.com/t/multiple-eventlisteners-modulus-and-rotating-cubes-performance-issues/319519>\
**Category:** Uncategorized\
**Created:** [February 23, 2011, 12:59pm UTC](https://forum.kirupa.com/t/multiple-eventlisteners-modulus-and-rotating-cubes-performance-issues/319519 "2011-02-23T12:59:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![f0rd](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@f0rd](https://forum.kirupa.com/u/f0rd)\
**Post date:** [February 23, 2011, 12:59pm UTC](https://forum.kirupa.com/t/multiple-eventlisteners-modulus-and-rotating-cubes-performance-issues/319519/1 "2011-02-23T12:59:10Z")

</div>

Hi everyone

I’ve created a grid of 3D cubes using modulus, and the 3d cubes are were created from the Math and Flash Tutorial, if you are interested it is [here](http://www.flashandmath.com/advanced/menu3d/).

What I am trying to accomplish (and it works, just the performance is lousy). All the cubes in the grid are inactive until the mouse hovers over them, then they start to rotate, and once the mouse moves off them they continue to rotate…

So to create the grid of cubes:

```auto
public function FlowerMenu(){
 
var rowY:Number = 0;
for (var i:int = 0; i < 190; i++) {
     var myCube = new CubeMenu(["anemon.jpg","parodia.jpg","anagallis.jpg","lila.jpg","cosm os.jpg","adonis.jpg"],100);
     myCube.x = 0 + ((i % 10) * 200);
     if (i % 10 == 0) {
         rowY += 200;
         }
myCube.y = rowY;
addChild(myCube);
}

```

No real issue there, all the cubes show up, tho if anybody has any improvements I would appreciate them.

Here is where the issue is, the mouse events & event listeners:

```auto
 private var i:int = 0;

private function setUpListeners():void
{
    spBoard.addEventListener(MouseEvent.MOUSE_OVER, boardOver);
    spBoard.addEventListener(MouseEvent.MOUSE_OUT, boardOut);
}

private function boardOver(e:MouseEvent):void
{
    addEventListener(Event.ENTER_FRAME, rotateSquare);
}

private function boardOut(e:MouseEvent):void
{
    addEventListener(Event.ENTER_FRAME, rotateSquare);
}

private function rotateSquare(e:Event)
{
    renderView(curTheta+i, curPhi+i); 
    i++;
}

```

So, this works, but after about 4 or 5 cubes have started rotating the  
performance drops considerably. I can imagine creating that many  
EventListeners isn’t a good idea, but I can’t see any other way of  
doing it.

Does anybody have any suggestions or code improvements, I’m very new to AS3 and Flash so any help or suggestions would be greatly appreciated.

Thanks in advance.
