package examples { import com.transmote.flar.FLARManager; import com.transmote.flar.marker.FLARMarkerEvent; import com.transmote.utils.time.FramerateDisplay; import examples.support.SimpleCubes_Away3DLite; import flash.display.Sprite; import flash.events.ErrorEvent; import flash.events.Event; /** * standard FLARToolkit Away3D Lite example, with our friends the Cubes. * * the Away3D Lite platform can be found here: * http://away3d.com/ * please note, usage of the Away3D platform is subject to Away3D's licensing. * * NOTE: this is not working accurately yet; * the camera settings are a manual approximation, * and do not reference FLARCameraParams.dat. * * @author Eric Socolofsky * @url http://transmote.com/flar */ public class FLARManagerExample_Away3DLite extends Sprite { private var flarManager:FLARManager; private var simpleCubes:SimpleCubes_Away3DLite; public function FLARManagerExample_Away3DLite () { this.init(); } private function init () :void { // pass the path to the FLARManager xml config file into the FLARManager constructor. // FLARManager creates and uses a FLARCameraSource by default. // the image from the first detected camera will be used for marker detection. this.flarManager = new FLARManager("../resources/flar/flarConfig.xml"); // handle any errors generated during FLARManager initialization. this.flarManager.addEventListener(ErrorEvent.ERROR, this.onFlarManagerError); // add FLARManager.flarSource to the display list to display the video capture. this.addChild(Sprite(this.flarManager.flarSource)); // begin listening for FLARMarkerEvents. this.flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED, this.onMarkerAdded); this.flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED, this.onMarkerUpdated); this.flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED, this.onMarkerRemoved); // framerate display helps to keep an eye on performance. var framerateDisplay:FramerateDisplay = new FramerateDisplay(); this.addChild(framerateDisplay); this.flarManager.addEventListener(Event.INIT, this.onFlarManagerInited); } private function onFlarManagerError (evt:ErrorEvent) :void { this.flarManager.removeEventListener(ErrorEvent.ERROR, this.onFlarManagerError); this.flarManager.removeEventListener(Event.INIT, this.onFlarManagerInited); trace(evt.text); // NOTE: developers can include better feedback to the end user here if desired. } private function onFlarManagerInited (evt:Event) :void { this.flarManager.removeEventListener(ErrorEvent.ERROR, this.onFlarManagerError); this.flarManager.removeEventListener(Event.INIT, this.onFlarManagerInited); this.simpleCubes = new SimpleCubes_Away3DLite(this.flarManager, this.stage.stageWidth, this.stage.stageHeight, this.stage); this.addChild(this.simpleCubes); // turn off interactivity in simpleCubes this.simpleCubes.mouseChildren = false; } private function onMarkerAdded (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] added"); this.simpleCubes.addMarker(evt.marker); } private function onMarkerUpdated (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] updated"); } private function onMarkerRemoved (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] removed"); this.simpleCubes.removeMarker(evt.marker); } } }