home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2011 May / ME_2011_05.iso / Galileo-Video-Tutorial / system / ChromeLINUX.swf / scripts / com / generationk / zinc / Window.as < prev   
Encoding:
Text File  |  2010-11-16  |  7.7 KB  |  253 lines

  1. package com.generationk.zinc
  2. {
  3.    import com.greensock.TweenMax;
  4.    import com.greensock.plugins.AutoAlphaPlugin;
  5.    import com.greensock.plugins.TweenPlugin;
  6.    import flash.display.DisplayObject;
  7.    import flash.display.GradientType;
  8.    import flash.display.Sprite;
  9.    import flash.events.Event;
  10.    import flash.events.MouseEvent;
  11.    import flash.geom.Matrix;
  12.    import flash.text.AntiAliasType;
  13.    import flash.text.TextField;
  14.    import flash.text.TextFieldAutoSize;
  15.    import flash.text.TextFormat;
  16.    
  17.    public class Window extends Sprite
  18.    {
  19.       public static var CANCEL:String = "cancel";
  20.       
  21.       private var _closeButton:CloseButton;
  22.       
  23.       private var _colors:Array;
  24.       
  25.       private var _textsTF:TextField;
  26.       
  27.       private var _closelabel:String;
  28.       
  29.       private var windowholder:Sprite;
  30.       
  31.       private var _cornerRadius:int;
  32.       
  33.       private var closebutton:Button;
  34.       
  35.       private var cancelbutton:DisplayObject;
  36.       
  37.       private var bglayer:Sprite;
  38.       
  39.       private var _height:Number;
  40.       
  41.       private var _width:Number;
  42.       
  43.       private var _background:Sprite;
  44.       
  45.       private var _title:String;
  46.       
  47.       private var _alpha:int;
  48.       
  49.       private var _texts:String;
  50.       
  51.       private var _linkedId:String;
  52.       
  53.       private var _cancellabel:String;
  54.       
  55.       private var _label:TextField;
  56.       
  57.       public function Window(param1:Number, param2:Number, param3:String, param4:String, param5:String, param6:String)
  58.       {
  59.          super();
  60.          TweenPlugin.activate([AutoAlphaPlugin]);
  61.          _closelabel = param6;
  62.          _cancellabel = param5;
  63.          _width = param1;
  64.          _height = param2;
  65.          _title = param3;
  66.          _texts = param4;
  67.          addEventListener(Event.ADDED_TO_STAGE,init);
  68.       }
  69.       
  70.       private function init(param1:Event) : void
  71.       {
  72.          drawBGLayer();
  73.          windowholder = new Sprite();
  74.          addChild(windowholder);
  75.          drawBackground();
  76.          addCloseButton();
  77.          addButtons();
  78.          addTitle(_title);
  79.          addText();
  80.          arrange();
  81.       }
  82.       
  83.       private function drawBackground() : void
  84.       {
  85.          _background = new Sprite();
  86.          _cornerRadius = 10;
  87.          _colors = [15856113,11776947];
  88.          _alpha = 0.5;
  89.          var _loc1_:String = GradientType.LINEAR;
  90.          var _loc2_:Matrix = new Matrix();
  91.          _loc2_.createGradientBox(_width,_height,Math.PI / 2,0,0);
  92.          trace("_width " + _width);
  93.          _background.graphics.beginGradientFill(_loc1_,_colors,[100,100],[0,255],_loc2_);
  94.          _background.graphics.drawRoundRect(0,0,_width,_height,_cornerRadius,_cornerRadius);
  95.          _background.graphics.endFill();
  96.          windowholder.addChild(_background);
  97.       }
  98.       
  99.       public function get linkedId() : String
  100.       {
  101.          return _linkedId;
  102.       }
  103.       
  104.       private function addButtons() : void
  105.       {
  106.          closebutton = new Button(_closelabel);
  107.          windowholder.addChild(closebutton);
  108.          closebutton.addEventListener(MouseEvent.CLICK,close);
  109.          cancelbutton = new Button(_cancellabel);
  110.          windowholder.addChild(cancelbutton);
  111.          cancelbutton.addEventListener(MouseEvent.CLICK,hide);
  112.       }
  113.       
  114.       private function arrange() : void
  115.       {
  116.          windowholder.x = Math.round(stage.stageWidth / 2);
  117.          windowholder.y = Math.round(stage.stageHeight / 2);
  118.          _background.x = Math.round(-(_background.width / 2));
  119.          _background.y = Math.round(-(_background.height / 2));
  120.          _closeButton.x = _background.x + _background.width - 10;
  121.          _closeButton.y = _background.y + 10;
  122.          _label.x = _background.x + 20;
  123.          _label.y = _background.y + 20;
  124.          closebutton.y = _background.y + _background.height - closebutton.height - 18;
  125.          cancelbutton.y = closebutton.y;
  126.          closebutton.x = _background.x + 22;
  127.          cancelbutton.x = closebutton.x + closebutton.width + 10;
  128.          _textsTF.x = Math.round(_background.x + 20);
  129.          _textsTF.y = Math.round(_background.y + _background.height / 2 - _textsTF.height / 2);
  130.          bglayer.graphics.clear();
  131.          bglayer.graphics.beginFill(0,0.4);
  132.          bglayer.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
  133.          bglayer.graphics.endFill();
  134.       }
  135.       
  136.       public function set title(param1:String) : void
  137.       {
  138.          var _loc2_:TextFormat = new TextFormat();
  139.          _loc2_.color = 1668518;
  140.          _loc2_.font = new BOLD().fontName;
  141.          _loc2_.size = 18;
  142.          _label.text = param1;
  143.          _label.setTextFormat(_loc2_);
  144.       }
  145.       
  146.       public function get windowWidth() : Number
  147.       {
  148.          return _width;
  149.       }
  150.       
  151.       public function get windowHeight() : Number
  152.       {
  153.          return _height;
  154.       }
  155.       
  156.       private function addTitle(param1:String) : void
  157.       {
  158.          var _loc2_:TextFormat = new TextFormat();
  159.          _loc2_.color = 1668518;
  160.          _loc2_.font = new BOLD().fontName;
  161.          _loc2_.bold = true;
  162.          _loc2_.size = 18;
  163.          _label = new TextField();
  164.          _label.autoSize = TextFieldAutoSize.LEFT;
  165.          _label.antiAliasType = AntiAliasType.ADVANCED;
  166.          _label.embedFonts = true;
  167.          _label.selectable = false;
  168.          _label.text = param1;
  169.          _label.setTextFormat(_loc2_);
  170.          windowholder.addChild(_label);
  171.       }
  172.       
  173.       public function hide(param1:MouseEvent = null) : void
  174.       {
  175.          dispatchEvent(new Event(CANCEL));
  176.          TweenMax.to(bglayer,0,{"autoAlpha":0});
  177.          TweenMax.to(windowholder,0.25,{
  178.             "autoAlpha":0,
  179.             "scaleX":0.8,
  180.             "scaleY":0.8
  181.          });
  182.       }
  183.       
  184.       private function drawBGLayer() : void
  185.       {
  186.          bglayer = new Sprite();
  187.          bglayer.graphics.beginFill(0,0.4);
  188.          bglayer.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
  189.          bglayer.graphics.endFill();
  190.          addChild(bglayer);
  191.       }
  192.       
  193.       public function hideDirect() : void
  194.       {
  195.          TweenMax.to(bglayer,0,{"autoAlpha":0});
  196.          TweenMax.to(windowholder,0,{
  197.             "autoAlpha":0,
  198.             "scaleX":0.8,
  199.             "scaleY":0.8
  200.          });
  201.       }
  202.       
  203.       private function addCloseButton() : void
  204.       {
  205.          _closeButton = new CloseButton();
  206.          _closeButton.addEventListener(MouseEvent.CLICK,hide);
  207.          windowholder.addChild(_closeButton);
  208.       }
  209.       
  210.       public function onResize() : void
  211.       {
  212.          arrange();
  213.       }
  214.       
  215.       private function addText() : void
  216.       {
  217.          var _loc1_:TextFormat = new TextFormat();
  218.          _loc1_.color = 0;
  219.          _loc1_.font = new BOLD().fontName;
  220.          _loc1_.bold = true;
  221.          _loc1_.size = 14;
  222.          _textsTF = new TextField();
  223.          _textsTF.antiAliasType = AntiAliasType.ADVANCED;
  224.          _textsTF.autoSize = TextFieldAutoSize.LEFT;
  225.          _textsTF.embedFonts = true;
  226.          _textsTF.selectable = false;
  227.          _textsTF.text = _texts;
  228.          _textsTF.setTextFormat(_loc1_);
  229.          windowholder.addChild(_textsTF);
  230.          arrange();
  231.       }
  232.       
  233.       private function close(param1:MouseEvent) : void
  234.       {
  235.          dispatchEvent(new Event(Event.CLOSE));
  236.          hide();
  237.       }
  238.       
  239.       public function show() : void
  240.       {
  241.          TweenMax.to(bglayer,0,{"autoAlpha":1});
  242.          windowholder.scaleX = 0.8;
  243.          windowholder.scaleY = 0.8;
  244.          TweenMax.to(windowholder,0.25,{
  245.             "autoAlpha":1,
  246.             "scaleX":1,
  247.             "scaleY":1
  248.          });
  249.       }
  250.    }
  251. }
  252.  
  253.