home *** CD-ROM | disk | FTP | other *** search
/ 360 Degrees of: Grand Canyon National Park / 360 Degrees of: Grand Canyon National Park.iso / pc / data / krpano / textfield.swf / scripts / textfield.as < prev   
Encoding:
Text File  |  2011-01-17  |  11.1 KB  |  307 lines

  1. package
  2. {
  3.    import flash.display.*;
  4.    import flash.events.*;
  5.    import flash.filters.*;
  6.    import flash.geom.*;
  7.    import flash.net.*;
  8.    import flash.system.*;
  9.    import flash.text.*;
  10.    import flash.utils.*;
  11.    import flash.xml.*;
  12.    
  13.    public class textfield extends Sprite
  14.    {
  15.       private var krpano:krpano_as3_interface = null;
  16.       
  17.       public var pluginpath:String = null;
  18.       
  19.       public var pluginobj:Object = null;
  20.       
  21.       public var bg:Shape = null;
  22.       
  23.       public var txt:TextField = null;
  24.       
  25.       public var txt_width:int = 400;
  26.       
  27.       public var txt_height:int = 300;
  28.       
  29.       public function textfield()
  30.       {
  31.          var txt:TextField = null;
  32.          var f:TextFormat = null;
  33.          var resizefu:Function = null;
  34.          super();
  35.          if(stage == null)
  36.          {
  37.             this.addEventListener(Event.ADDED_TO_STAGE,this.startplugin);
  38.             this.addEventListener(Event.UNLOAD,this.stopplugin);
  39.          }
  40.          else
  41.          {
  42.             stage.scaleMode = StageScaleMode.NO_SCALE;
  43.             stage.align = StageAlign.TOP_LEFT;
  44.             txt = new TextField();
  45.             txt.textColor = 16777215;
  46.             txt.selectable = false;
  47.             txt.htmlText = "krpano " + "1.0.8.12" + "\n\n" + "<b>textfield plugin</b>" + "\n\n" + "(build " + "CUSTOM" + ")";
  48.             f = new TextFormat();
  49.             f.font = "_sans";
  50.             f.size = 14;
  51.             txt.autoSize = f.align = "center";
  52.             txt.setTextFormat(f);
  53.             addChild(txt);
  54.             resizefu = function(param1:Event):void
  55.             {
  56.                txt.x = (stage.stageWidth - txt.width) / 2;
  57.                txt.y = (stage.stageHeight - txt.height) / 2;
  58.             };
  59.             stage.addEventListener(Event.RESIZE,resizefu);
  60.             resizefu(null);
  61.          }
  62.       }
  63.       
  64.       private function startplugin(param1:Event) : void
  65.       {
  66.          this.removeEventListener(Event.ADDED_TO_STAGE,this.startplugin);
  67.          if(this.krpano == null)
  68.          {
  69.             this.krpano = krpano_as3_interface.getInstance();
  70.             if(this.krpano.get("version") < "1.0.8")
  71.             {
  72.                this.krpano.call("error(textfield plugin - wrong krpano version - min. 1.0.8 needed);");
  73.                return;
  74.             }
  75.             this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent);
  76.             this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_RESIZE,this.resizeEvent);
  77.             this.krpano.addPluginEventListener(this,krpano_as3_interface.PLUGINEVENT_UPDATE,this.updateEvent);
  78.          }
  79.       }
  80.       
  81.       private function stopplugin(param1:Event) : void
  82.       {
  83.          this.txt.removeEventListener(TextEvent.LINK,this.link_event);
  84.          this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_REGISTER,this.registerEvent);
  85.          this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_RESIZE,this.resizeEvent);
  86.          this.krpano.removePluginEventListener(this,krpano_as3_interface.PLUGINEVENT_UPDATE,this.updateEvent);
  87.          removeChild(this.bg);
  88.          this.bg = null;
  89.          removeChild(this.txt);
  90.          this.txt = null;
  91.          this.krpano = null;
  92.       }
  93.       
  94.       private function registerEvent(param1:DataEvent) : void
  95.       {
  96.          this.pluginpath = param1.data;
  97.          this.pluginobj = this.krpano.get(this.pluginpath);
  98.          this.pluginobj.registerattribute("html","");
  99.          this.pluginobj.registerattribute("css","");
  100.          this.pluginobj.registerattribute("autosize","none");
  101.          this.pluginobj.registerattribute("wordwrap",true);
  102.          this.pluginobj.registerattribute("background",true);
  103.          this.pluginobj.registerattribute("backgroundcolor",16777215);
  104.          this.pluginobj.registerattribute("backgroundalpha",1);
  105.          this.pluginobj.registerattribute("border",false);
  106.          this.pluginobj.registerattribute("bordercolor",0);
  107.          this.pluginobj.registerattribute("borderwidth",1);
  108.          this.pluginobj.registerattribute("roundedge",0);
  109.          this.pluginobj.registerattribute("selectable",true);
  110.          this.pluginobj.registerattribute("glow",0);
  111.          this.pluginobj.registerattribute("glowcolor",16777215);
  112.          this.pluginobj.registerattribute("blur",0);
  113.          this.pluginobj.registerattribute("shadow",0);
  114.          this.pluginobj.registerattribute("textglow",0);
  115.          this.pluginobj.registerattribute("textglowcolor",16777215);
  116.          this.pluginobj.registerattribute("textblur",0);
  117.          this.pluginobj.registerattribute("textshadow",0);
  118.          this.pluginobj.update = this.updateHTML;
  119.          this.bg = new Shape();
  120.          this.txt = new TextField();
  121.          this.txt.htmlText = "";
  122.          this.txt.multiline = true;
  123.          this.txt.wordWrap = true;
  124.          this.txt.border = false;
  125.          this.txt.background = false;
  126.          this.txt.condenseWhite = true;
  127.          this.txt.width = this.txt_width;
  128.          this.txt.height = this.txt_height;
  129.          this.txt.addEventListener(TextEvent.LINK,this.link_event);
  130.          this.addChild(this.bg);
  131.          this.addChild(this.txt);
  132.          this.updateSTYLE();
  133.          this.updateHTML();
  134.       }
  135.       
  136.       private function updateEvent(param1:DataEvent) : void
  137.       {
  138.          var _loc2_:* = "." + String(param1.data) + ".";
  139.          var _loc3_:String = ".html.css.";
  140.          var _loc4_:String = ".autosize.wordwrap.background.backgroundcolor.backgroundalpha.border.bordercolor.borderwidth.roundedge.selectable.glow.blur.shadow.textglow.textblur.textshadow.";
  141.          if(_loc3_.indexOf(_loc2_) >= 0)
  142.          {
  143.             this.updateHTML();
  144.          }
  145.          else if(_loc4_.indexOf(_loc2_) >= 0)
  146.          {
  147.             this.updateSTYLE();
  148.          }
  149.       }
  150.       
  151.       private function resizeEvent(param1:DataEvent) : void
  152.       {
  153.          var _loc3_:int = 0;
  154.          var _loc4_:int = 0;
  155.          var _loc2_:String = param1.data;
  156.          _loc3_ = parseInt(_loc2_);
  157.          _loc4_ = parseInt(_loc2_.slice(_loc2_.indexOf("x") + 1));
  158.          this.txt.width = _loc3_;
  159.          this.txt.height = _loc4_;
  160.          this.txt_width = _loc3_;
  161.          this.txt_height = _loc4_;
  162.          this.updateSTYLE();
  163.       }
  164.       
  165.       private function link_event(param1:TextEvent) : void
  166.       {
  167.          this.krpano.call(param1.text,null,this.pluginobj);
  168.       }
  169.       
  170.       private function updateSTYLE() : void
  171.       {
  172.          switch(String(this.pluginobj.autosize).toLowerCase())
  173.          {
  174.             case "true":
  175.             case "auto":
  176.             case "left":
  177.                this.txt.autoSize = "left";
  178.                break;
  179.             case "center":
  180.                this.txt.autoSize = "center";
  181.                break;
  182.             case "right":
  183.                this.txt.autoSize = "right";
  184.                break;
  185.             case "none":
  186.             default:
  187.                this.txt.autoSize = "none";
  188.          }
  189.          this.txt.wordWrap = this.pluginobj.wordwrap;
  190.          this.txt.selectable = this.pluginobj.selectable;
  191.          this.bg.alpha = this.pluginobj.backgroundalpha;
  192.          this.bg.graphics.clear();
  193.          if(Boolean(this.pluginobj.background) || Boolean(this.pluginobj.border))
  194.          {
  195.             if(this.pluginobj.borderwidth > 0)
  196.             {
  197.                this.bg.graphics.lineStyle(this.pluginobj.borderwidth,this.pluginobj.bordercolor);
  198.             }
  199.             if(this.pluginobj.background)
  200.             {
  201.                this.bg.graphics.beginFill(this.pluginobj.backgroundcolor);
  202.             }
  203.             if(this.pluginobj.roundedge <= 0)
  204.             {
  205.                this.bg.graphics.drawRect(0,0,this.txt_width,this.txt_height);
  206.             }
  207.             else
  208.             {
  209.                this.bg.graphics.drawRoundRect(0,0,this.txt_width,this.txt_height,this.pluginobj.roundedge);
  210.             }
  211.          }
  212.          var _loc1_:Array = new Array();
  213.          if(this.pluginobj.glow > 0)
  214.          {
  215.             _loc1_.push(new GlowFilter(this.pluginobj.glowcolor,1,this.pluginobj.glow,this.pluginobj.glow));
  216.          }
  217.          if(this.pluginobj.blur > 0)
  218.          {
  219.             _loc1_.push(new BlurFilter(this.pluginobj.blur,this.pluginobj.blur));
  220.          }
  221.          if(this.pluginobj.shadow > 0)
  222.          {
  223.             _loc1_.push(new DropShadowFilter(this.pluginobj.shadow));
  224.          }
  225.          this.bg.filters = _loc1_.length > 0 ? _loc1_ : null;
  226.          var _loc2_:Array = new Array();
  227.          if(this.pluginobj.textglow > 0)
  228.          {
  229.             _loc2_.push(new GlowFilter(this.pluginobj.textglowcolor,1,this.pluginobj.textglow,this.pluginobj.textglow));
  230.          }
  231.          if(this.pluginobj.textblur > 0)
  232.          {
  233.             _loc2_.push(new BlurFilter(this.pluginobj.textblur,this.pluginobj.textblur));
  234.          }
  235.          if(this.pluginobj.textshadow > 0)
  236.          {
  237.             _loc2_.push(new DropShadowFilter(this.pluginobj.textshadow));
  238.          }
  239.          this.txt.filters = _loc2_.length > 0 ? _loc2_ : null;
  240.       }
  241.       
  242.       private function str_replace(param1:String, param2:String, param3:String) : String
  243.       {
  244.          var _loc4_:Array = param1.split(param2);
  245.          return _loc4_.join(param3);
  246.       }
  247.       
  248.       private function updateHTML() : void
  249.       {
  250.          var _loc4_:Timer = null;
  251.          var _loc1_:StyleSheet = new StyleSheet();
  252.          var _loc2_:String = this.pluginobj.css;
  253.          var _loc3_:String = this.pluginobj.html;
  254.          if(_loc2_ == null || _loc2_ == "")
  255.          {
  256.             this.txt.styleSheet = null;
  257.          }
  258.          else
  259.          {
  260.             if(_loc2_.indexOf("data:") == 0)
  261.             {
  262.                _loc2_ = this.krpano.get("data[" + _loc2_.slice(5) + "].content");
  263.             }
  264.             else
  265.             {
  266.                _loc2_ = unescape(_loc2_);
  267.             }
  268.             _loc1_.parseCSS(_loc2_);
  269.             this.txt.styleSheet = _loc1_;
  270.          }
  271.          if(_loc3_.indexOf("data:") == 0)
  272.          {
  273.             _loc3_ = this.krpano.get("data[" + _loc3_.slice(5) + "].content");
  274.          }
  275.          else
  276.          {
  277.             _loc3_ = this.str_replace(_loc3_,"[","<");
  278.             _loc3_ = this.str_replace(_loc3_,"]",">");
  279.             _loc3_ = unescape(_loc3_);
  280.          }
  281.          if(_loc3_ == null)
  282.          {
  283.             _loc3_ = "";
  284.          }
  285.          this.txt.htmlText = _loc3_;
  286.          if(this.txt.autoSize != "none")
  287.          {
  288.             this.txt_height = this.txt.height;
  289.             this.pluginobj.height = this.txt_height;
  290.             _loc4_ = new Timer(0.001,1);
  291.             _loc4_.addEventListener("timer",this.updateSIZE);
  292.             _loc4_.start();
  293.          }
  294.          this.pluginobj.textheight = this.txt_height;
  295.       }
  296.       
  297.       private function updateSIZE(param1:TimerEvent = null) : void
  298.       {
  299.          this.txt_height = this.txt.height;
  300.          this.pluginobj.height = this.txt_height;
  301.          this.pluginobj.textheight = this.txt.textHeight;
  302.          this.updateSTYLE();
  303.       }
  304.    }
  305. }
  306.  
  307.