Menu
Samaritan's Purse

OBJECT MOVE

Object Move

CODE

´╗┐package
{
    import flash.events.KeyboardEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.ui.Keyboard;

    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.view.BasicView;

    public class Papervision3DObjectMove extends BasicView
    {
        private var object :Plane;
        private var field :TextField;

        public function Papervision3DObjectMove()
        {
            object = new Plane(new ColorMaterial(0xff0000));
            scene.addChild(object);

            var object2 :Plane = new Plane(new ColorMaterial(0x00ff00));
            object2.z         = 1000;
            scene.addChild(object2);

            field                 = new TextField();
            field.autoSize         = TextFieldAutoSize.LEFT;
            field.defaultTextFormat = new TextFormat("verdana");
            field.selectable        = false;
            addChild(field);

            stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

            singleRender();
            instructions();
        }

        private function handleKeyDown(e:KeyboardEvent):void
        {
            switch (e.keyCode) {
                case Keyboard.ENTER:
                    object.x = 0;
                    object.y = 0;
                    object.z = 0;
                    break;
                case "Q".charCodeAt():
                    object.moveRight(10);
                    break;
                case "A".charCodeAt():
                    object.moveLeft(10);
                    break;
                case "W".charCodeAt():
                    object.moveUp(10);
                    break;
                case "S".charCodeAt():
                    object.moveDown(10);
                    break;
                case "E".charCodeAt():
                    object.moveForward(10);
                    break;
                case "D".charCodeAt():
                    object.moveBackward(10);
                    break;
            }

            singleRender();
            instructions();
        }

        private function instructions():void
        {
            field.text = "Click\tStart"
                + "\nEnter\tReset"
                + "\nQ\t\tObject Move Right"
                + "\nA\t\tObject Move Left"
                + "\nW\t\tObject Move Up"
                + "\nS\t\tObject Move Down"
                + "\nE\t\tObject Move Forward"
                + "\nD\t\tObject Move Backward"
                + "\n\nObject:"
                + "\nX:\t" + object.x
                + "\nY:\t" + object.y
                + "\nZ:\t" + object.z;
        }
    }
}

Download