Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>New Answer:</h2> <p>In this case you can put every cube that you want to rotate in a Array and call ENTER_FRAME on the a container clip (not for every cube).</p> <p>Looping through your Array (in the container) will be faster than dispatching tons of ENTER_FRAME events (I think).</p> <p>(ask for examples if you need ;D)</p> <hr> <h2>Example</h2> <p>Assuming <code>renderView</code> is a method of MenuCube, I suggest that you put all code needed for rotation inside <code>renderView</code> (information like <code>i++</code>, <code>curTheta</code> and <code>curPhi</code>).</p> <pre><code>// The container where every cube will reside public var CubeContainer:Sprite; // Creating Cubes, setting a listener to rotate them on MOUSE_OVER // and adding them to the container. public function CreateCubes() { CubeContainer = new Sprite(); for (var i:int = 0; i &lt; 10; i++) { var NewCube = new CubeMenu(/*...*/); NewCube.addEventListener(MouseEvent.MOUSE_OVER, RotateMe); CubeContainer.addChild(NewCube); } CubeContainer.addEventListener(Event.ENTER_FRAME, RotateCubes); } // When MOUSE_OVER fires, start rotating (by pushing it into an Array) // and remove MOUSE_OVER listener public function RotateMe(e:MouseEvent):void { var TargetCube:CubeMenu = e.currentTarget; CubesToRotate.push(TargetCube); TargetCube.removeEventListener(MouseEvent.MOUSE_OVER, RotateMe); } // ENTER_FRAME of the container... // This will check every container that need to be rotated // and call renderView for it. public function RotateCubes(e:Event):void { for(var i:int = 0; i &lt;= CubesToRotate.length; i++) { var CurrentCube:CubeMenu = CubesToRotate[i]; CurrentCube.renderView(); } } </code></pre> <hr> <h2>Old answer:</h2> <p>If I got it right, you can use MOUSE_OVER and MOUSE_OUT events:</p> <pre><code>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 { removeEventListener(Event.ENTER_FRAME, rotateSquare); } private function rotateSquare(e:Event) { renderView(curTheta+i, curPhi+i); i++; } </code></pre> <p>This way your Mouse Events will be dispatched <em>only</em> when you move your mouse over and out the <code>spBoard</code>.</p> <p>ps: As you see, the <code>i</code> variable must be defined outside the functions for this to work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload