/* HTML textfield plugin - version: 0.1 - min. krpano version: 1.0.6 krpano.com */ package { import flash.display.*; import flash.events.*; import flash.system.*; import flash.net.*; import flash.filters.*; import flash.geom.*; import flash.text.*; import flash.utils.*; import flash.xml.*; import flash.ui.Mouse; import krpano_as3_interface; [SWF(width="400", height="300", backgroundColor="#FFFFFF")] public class textfield extends Sprite { // krpano as3 interface private var krpano:krpano_as3_interface = null; public var pluginname:String = null; public var bg:Shape = null; public var txt:TextField = null; public var txt_width:int = 400; public var txt_height:int = 300; public function textfield() { if (stage == null) { this.addEventListener(Event.ADDED_TO_STAGE, startplugin); this.addEventListener(Event.REMOVED_FROM_STAGE, stopplugin); } } // start of plugin private function startplugin(evt:Event):void { // get krpano interface krpano = krpano_as3_interface.getInstance(); if ( krpano.get("version") < "1.0.6") { krpano.call("error(textfield plugin - too old krpano version);"); return; } // start debugmode / open log //krpano.trace(0xFF,"start debug mode"); //krpano.trace(0,"textfield.startplugin"); // add plugin listeners // register event to get plugins name krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent); // resize event to set the size of the textfield krpano.addPluginEventListener(this, krpano_as3_interface.PLUGINEVENT_RESIZE, resizeEvent); } private function stopplugin(evt:Event):void { //krpano.trace(0,"textfield.stopplugin"); // remove textfield link event listener txt.removeEventListener(TextEvent.LINK, link_event); // remove event listeners krpano.removePluginEventListener(this, krpano_as3_interface.PLUGINEVENT_REGISTER, registerEvent); krpano.removePluginEventListener(this, krpano_as3_interface.PLUGINEVENT_RESIZE, resizeEvent); // remove all removeChild(bg); bg = null; removeChild(txt); txt = null; krpano = null; } private function registerEvent(evt:DataEvent):void { // register event - "data" is the name of the plugin pluginname = "plugin[" + evt.data + "]"; //krpano.trace(0,"textfield.registerEvent - pluginname=" + pluginname); // textfield's background bg = new Shape(); // textfield txt = new TextField(); txt.htmlText = ""; txt.multiline = true; txt.wordWrap = true; txt.border = false; txt.background = false; txt.condenseWhite = true; txt.width = txt_width; txt.height = txt_height; // textfield link event listener txt.addEventListener(TextEvent.LINK, link_event); // add background and textfield this.addChild(bg); this.addChild(txt); // update content updateSTYLE(); updateHTML(); // add a function named "update" // - this parses the html and css // - call it from xml with "call(plugin[name].update);" krpano.set(pluginname+".update", updateHTML); var customattributes:String = ""; // set the custom attributes of this plugin (needed for the editor plugin for correct working) customattributes = "html,css," + "autosize,background,backgroundcolor,bordercolor,borderwidth,roundedge,selectable," + "glow,blur,shadow,textglow,textblur,textshadow"; krpano.set(pluginname + ".customattributes",customattributes); } private function link_event(textevent:TextEvent):void { krpano.call( textevent.text ); } private function resizeEvent(dataevent:DataEvent):void { //krpano.trace(0,"textfield.resizeEvent - size=" + dataevent.data); var resizesize:String = dataevent.data; // size has format WIDTHxHEIGHT var width:int; var height:int; width = parseInt(resizesize); height = parseInt(resizesize.slice(resizesize.indexOf("x")+1)); txt.width = width; txt.height = height; // save size txt_width = width; txt_height = height; // update bg shape updateSTYLE(); } private function updateSTYLE():void { var autosize : String = "none"; var background : Boolean = true; var bordercolor : int = 0x000000; var borderwidth : int = 1; var bgcolor : int = 0xFFFFFF; var roundrect : Number = 0; // parameters for get's var param:* = null; // get autosize param = krpano.get(pluginname + ".autosize"); if (param != undefined && param != "") autosize = String( param ).toLowerCase(); txt.autoSize = autosize; // get background param = krpano.get(pluginname + ".background"); if (param != undefined && param != "") background = String( param ).toLowerCase() != "false"; // get backgroundcolor param = krpano.get(pluginname + ".backgroundcolor"); if (param != undefined && param != "") bgcolor = int( param ); // get bordercolor param = krpano.get(pluginname + ".bordercolor"); if (param != undefined && param != "") bordercolor = int( param ); // get borderwidth param = krpano.get(pluginname + ".borderwidth"); if (param != undefined && param != "") borderwidth = int( param ); // get roundedge param = krpano.get(pluginname + ".roundedge"); if (param != undefined && param != "") roundrect = Number( param ); // get selectable param = krpano.get(pluginname + ".selectable"); if (param != undefined && param != "") { txt.selectable = (String(param).toLowerCase() == "true"); } bg.graphics.clear(); if (background) { bg.graphics.lineStyle(borderwidth, bordercolor); bg.graphics.beginFill(bgcolor); if (roundrect == 0) bg.graphics.drawRect(0,0,txt_width,txt_height); else bg.graphics.drawRoundRect(0,0,txt_width,txt_height,roundrect); } // apply filters var filters:Array = new Array(); param = krpano.get(pluginname + ".glow"); if (param != undefined && param != "") { // parameter is distance filters.push( new GlowFilter( int(param) ) ); } param = krpano.get(pluginname + ".blur"); if (param != undefined && param != "") { // parameter is distance filters.push( new BlurFilter( int(param), int(param) ) ); } param = krpano.get(pluginname + ".shadow"); if (param != undefined && param != "") { // parameter is distance filters.push( new DropShadowFilter( int(param) ) ); } if (filters.length > 0) bg.filters = filters; else bg.filters = null; // apply textfilters var textfilters:Array = new Array(); param = krpano.get(pluginname + ".textglow"); if (param != undefined && param != "") { // parameter is distance textfilters.push( new GlowFilter( int(param) ) ); } param = krpano.get(pluginname + ".textblur"); if (param != undefined && param != "") { // parameter is distance textfilters.push( new BlurFilter( int(param), int(param) ) ); } param = krpano.get(pluginname + ".textshadow"); if (param != undefined && param != "") { // parameter is distance textfilters.push( new DropShadowFilter( int(param) ) ); } if (textfilters.length > 0) txt.filters = textfilters; else txt.filters = null; } private function updateHTML():void { var css:StyleSheet = new StyleSheet(); var cssdata :String = krpano.get(pluginname + ".css"); var htmldata:String = krpano.get(pluginname + ".html"); if (cssdata == null || cssdata == "") { txt.styleSheet = null; } else { if (cssdata.indexOf("data:") == 0 ) { cssdata = krpano.get("data[" + cssdata.slice(5) + "]"); } else { cssdata = unescape(cssdata); } css.parseCSS( cssdata ); txt.styleSheet = css; } if (htmldata.indexOf("data:") == 0 ) { htmldata = krpano.get("data[" + htmldata.slice(5) + "]"); } else { htmldata = unescape(htmldata); } txt.htmlText = htmldata; if (txt.autoSize != "none") { // save size //txt_width = txt.width; txt_height = txt.height; krpano.set(pluginname + ".height", txt_height); // update bg shape //updateSTYLE(); } } } }