/* krpano as3 plugin example / template for mxmlc (.as) */ package { import flash.display.*; import flash.text.*; import flash.events.*; import flash.utils.*; import flash.system.*; [SWF(width="400", height="300", backgroundColor="#000000")] public class plugintemplate extends Sprite { public var krpano : Object = null; public var plugin : Object = null; public function plugintemplate() { if (stage == null) { // startup when loaded inside krpano this.addEventListener(Event.ADDED_TO_STAGE, versioncheck); } else { // direct startup - show plugin version info stage.scaleMode = "noScale"; stage.align = "TL"; var txt:TextField = new TextField(); txt.defaultTextFormat = new TextFormat("_sans",14,0xFFFFFF,false,false,false,null,null,"center"); txt.autoSize = "center"; txt.htmlText = "krpano\n\nplugintemplate plugin"; addChild(txt); var resizefu:Function = function(event:Event=null):void { txt.x = (stage.stageWidth - txt.width )/2; txt.y = (stage.stageHeight - txt.height)/2; } stage.addEventListener(Event.RESIZE, resizefu); resizefu(); } } private function versioncheck(evt:Event):void { // compatibility check of the krpano version by using the old plugin interface: // - the "version" must be at least "1.0.8.14" // - and the "build" must be "2011-05-10" or greater this.removeEventListener(Event.ADDED_TO_STAGE, versioncheck); var oldkrpanointerface:Object = (getDefinitionByName("krpano_as3_interface") as Class)["getInstance"](); if (oldkrpanointerface.get("version") < "1.0.8.14" || oldkrpanointerface.get("build") < "2011-05-10") { oldkrpanointerface.trace(3, "plugintemplate plugin - too old krpano viewer version (min. 1.0.8.14)"); } } // registerplugin // - the start for the plugin // - this function will be called from krpano when the plugin will be loaded public function registerplugin(krpanointerface:Object, pluginfullpath:String, pluginobject:Object):void { // get the krpano interface and the plugin object krpano = krpanointerface; plugin = pluginobject; // add plugin attributes and functions // some example attributes: plugin.registerattribute("attr1", "defaultvalue"); plugin.registerattribute("attr2", 123.456); plugin.registerattribute("attr3", false); plugin.registerattribute("attr4", 10, attr4_setter, attr4_getter); // add a from xml callable functions: plugin.testfunction1 = testfunction1; plugin.testfunction2 = testfunction2; plugin.testfunction3 = testfunction3; // say hello krpano.trace(1,"hello from plugin[" + plugin.name + "]"); // add plugin graphic content / child objects (optionally) if(0) // 'if(0)' means that this code will not be executed, the code here is only an example for how-to add addtional graphical content! { // register the size of the plugin content (optionally) // e.g. to set the plugin source size to 256x256 pixels: plugin.registercontentsize(256,256); // the plugin itself is already a Flash Sprite Object, // so to add addtional Flash DisplayObjects // just add them to the plugin itself: var exampleChildSprite:Sprite = new Sprite(); this.addChild(exampleChildSprite); } } // unloadplugin // - the end for the plugin // - this function will be called from krpano when the plugin will be removed public function unloadplugin():void { // remove all your custom plugin stuff here // ... plugin = null; krpano = null; } // onresize (optionally) // - this function will be called from krpano when the plugin will be resized // - can be used to resize sub elements manually // return: // - return true to let krpano scale the plugin automatically // - return false to disable any automatic scaling public function onresize(width:int, height:int):Boolean { // ... return false; // don't do any automatically scaling } // example setter/getter function and plugin functions: private var attr4:Number = 10.0; private function attr4_setter(newvalue:Number):void { krpano.trace(1,"attr4 will be changed from " + attr4 + " to " + newvalue); attr4 = newvalue; } private function attr4_getter():Number { return attr4; } private function testfunction1(...rest):void { // trace the given arguments krpano.trace(1,"testfunction1() called with " + rest.length + " arguments:"); for (var i:int=0; i