I have an on enter frame listener defined in a function:
function sideClicked(e:MouseEvent):void {
removeEventListener(Event.ENTER_FRAME, loop);
var targetName=e.target.name;
var a:Array=[];
a=targetName.split("_");
turnto = cube1["turn"+a[1]]();
addEventListener(Event.ENTER_FRAME, looptoposition);
}
The looptoposition() function simple calls a function from a custom class repetitively to move an object until it reaches its position. This is the function it calls from the included custom class:
public function rotateToPos(a:Number,b:Number,c:Number):void {
if(!cubeReady){return;}
if(cube.rotationY<b){
cube.rotationY+=3;
}
else if(cube.rotationY>b){
cube.rotationY-=3;
}
sortFaces();
updateShadow();
}
This gets the desired result visually - the cube rotates until the chosen point and then stops - however the listener continues. I have two problems:
-
I would like to remove the listener but can’t seem to do so from the imported class - I’m having trouble referencing my functions in the root flash file.
-
I also need to declare that the function has completed - but the equalities mean that b is either greater or less than but never equal to? Whats a better way of getting the cube to rotate to a set position on each frame? The reason for the equalities are the cube can turn two different directions. So rotation could be negative.