MXML component class

package {
import aerys.minko.render.Viewport;
import aerys.minko.scene.controller.camera.ArcBallController;
import aerys.minko.scene.node.Scene;
import aerys.minko.scene.node.camera.Camera;

import flash.events.Event;
import flash.geom.Point;

import mx.core.UIComponent;
[Event(name="minkoReady", type="Stage3DEvent")]
public class MinkoFlexContainer extends UIComponent {
private var _viewport:Viewport = new Viewport();
private var _camera:Camera = null;
private var _cameraController:ArcBallController = null;
private var _scene:Scene = new Scene();
private var _cursor:Point = new Point();
private var _added:Boolean = false;
public function MinkoFlexContainer() {
this.addEventListener(Event.ADDED_TO_STAGE, handleAdded);
}
private function handleAdded(event:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, handleAdded);
invalidateProperties();
}
public function get viewport():Viewport {
return _viewport;
}
public function get camera():Camera {
return _camera;
}
public function get cameraController():ArcBallController {
return _cameraController;
}
public function get scene():Scene {
return _scene;
}

override public function initialize():void {
super.initialize();
invalidateProperties();
}
override protected function createChildren():void {
super.createChildren();
invalidateProperties();
}
override protected function commitProperties():void {
super.commitProperties();
if (stage) {
if (!_added) {
_added = true;
stage.addChildAt(_viewport, 0);
_viewport.backgroundColor = 0x666666ff;
initializeScene();
initializeUI();
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
dispatchEvent(new Stage3DEvent(Stage3DEvent.MINKO_READY, true, true));
}
}
}
protected function initializeScene():void {
_camera = new Camera();
_cameraController = new ArcBallController();
_cameraController.bindDefaultControls(_viewport);
_cameraController.minDistance = 1;
_cameraController.yaw = Math.PI * -.5;
_cameraController.pitch = Math.PI / 2;
_cameraController.distance = 5;
camera.addController(_cameraController);
_scene.addChild(camera);
}
protected function initializeUI():void {
}
protected function enterFrameHandler(event:Event):void {
_scene.render(_viewport);
}
}
}

Event notifying about engine being initialized


package {
import flash.events.Event;
public class Stage3DEvent extends Event{
public static const MINKO_READY:String="minkoReady";
public function Stage3DEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
}
}
}

Implementation of the component


















Categories: Blog

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.