Native3D Drag Test
/**
* Copyright 9balls ( http://wonderfl.net/user/9balls )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cUeP
*/
package {
import com.bit101.components.NumericStepper;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author
*/
public class Main extends Sprite {
private var dragObject:Sprite;
private var dragParent:Sprite;
public function Main():void {
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
dragObject = new Sprite();
dragObject.graphics.beginFill(0xFF0000);
dragObject.graphics.drawRect(-20, -20, 40, 40);
dragObject.graphics.endFill();
dragObject.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
dragObject.x = 200;
dragObject.y = 200;
dragObject.z = 0;/////////////これ大事
//
dragParent = new Sprite();
dragParent.rotationX = 0;
dragParent.addChild(dragObject);
this.addChild(dragParent);
//
var stepper:NumericStepper = new NumericStepper(this, 20, 20, onStep);
stepper.minimum = 0;
stepper.maximum = 120;
stepper.step = 10;
}
public function onStep(e:Event):void {
dragParent.rotationX = (e.currentTarget as NumericStepper).value;
}
public function onMouseDown(e:MouseEvent):void {
dragObject.startDrag();
}
public function onMouseUp(e:MouseEvent):void {
dragObject.stopDrag();
}
}
}