flashactionscript3dflash-cs5cs4

Flash CS5 3D cube center point doesn't work


I am using the action script below to rotate my cube.

I how ever have the problem of it rotating from the wrong center point even though I have set it to the middle.

I am aware that this can be done using action script just wondering about the syntax or any simple suggestions.

function cubeRotate(e:Event){
    mycube3d.rotationY = mycube3d.rotationY+1;
    mycube3d.rotationX = mycube3d.rotationX+1;

}
stage.addEventListener(Event.ENTER_FRAME,cubeRotate);

Solution

  • setRegPoint(book, book.width / 2, book.height / 2);
    
    function setRegPoint(obj:DisplayObjectContainer, newX:Number, NewY:Number):void {
    
        var bounds:Rectangle = obj.getBounds(obj.parent);
        var currentRegZ:Number = obj.z - bounds.top;
    
        var zOffset:Number = -50 - currentRegZ;
    
        obj.z += zOffset;
    
        for(var i:int = 0; i < obj.numChildren; i++) {
            obj.getChildAt(i).z -= zOffset;
        }
    }
    
    function cubeRotate(e:Event){    
      book.rotationY = book.rotationY+1    
      book.rotationX = book.rotationX+1    
    }
    
    stage.addEventListener(Event.ENTER_FRAME,cubeRotate)