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 / Button.as next >
Encoding:
Text File  |  2010-11-16  |  4.2 KB  |  134 lines

  1. package com.generationk.zinc
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.events.MouseEvent;
  5.    import flash.text.AntiAliasType;
  6.    import flash.text.TextField;
  7.    import flash.text.TextFormat;
  8.    
  9.    public class Button extends Sprite
  10.    {
  11.       private var _border:Rect;
  12.       
  13.       private var _background:GradientRectangle;
  14.       
  15.       private var _backgroundHL:GradientRectangle;
  16.       
  17.       private var _label:TextField;
  18.       
  19.       private var _overlay:Rect;
  20.       
  21.       public function Button(param1:String)
  22.       {
  23.          super();
  24.          buttonMode = true;
  25.          drawBorder();
  26.          drawBackground();
  27.          addLabel(param1);
  28.          mouseChildren = false;
  29.          addEventListener(MouseEvent.MOUSE_OVER,onOver);
  30.          addEventListener(MouseEvent.MOUSE_OUT,onOut);
  31.       }
  32.       
  33.       private function onOver(param1:MouseEvent) : void
  34.       {
  35.          _backgroundHL.visible = true;
  36.          _background.visible = false;
  37.       }
  38.       
  39.       public function set activate(param1:Boolean) : void
  40.       {
  41.          if(!param1)
  42.          {
  43.             _overlay.alpha = 0.5;
  44.             _background.alpha = 0.5;
  45.             removeEventListener(MouseEvent.MOUSE_OVER,onOver);
  46.             removeEventListener(MouseEvent.MOUSE_OUT,onOut);
  47.             buttonMode = false;
  48.          }
  49.          else
  50.          {
  51.             addEventListener(MouseEvent.MOUSE_OVER,onOver);
  52.             addEventListener(MouseEvent.MOUSE_OUT,onOut);
  53.             _background.alpha = 1;
  54.             _overlay.alpha = 1;
  55.             buttonMode = true;
  56.          }
  57.       }
  58.       
  59.       private function addLabel(param1:String) : void
  60.       {
  61.          var _loc2_:TextFormat = new TextFormat();
  62.          _loc2_.color = 3355443;
  63.          _loc2_.font = new BOLD().fontName;
  64.          _loc2_.bold = true;
  65.          _loc2_.size = 14;
  66.          _label = new TextField();
  67.          _label.antiAliasType = AntiAliasType.ADVANCED;
  68.          _label.embedFonts = true;
  69.          _label.selectable = false;
  70.          _label.x = 10;
  71.          _label.text = param1;
  72.          _label.setTextFormat(_loc2_);
  73.          _label.width = _label.textWidth + 5;
  74.          _label.height = _label.textHeight + 5;
  75.          addChild(_label);
  76.          _border.draw(Math.round(_label.textWidth + 22),25);
  77.          _background.draw(_border.width - 2,23);
  78.          _backgroundHL.draw(_border.width - 2,23);
  79.          _label.x = _background.width / 2 - _label.textWidth / 2 - 2;
  80.          _label.y = _background.height / 2 - _label.textHeight / 2;
  81.          addOverlay();
  82.       }
  83.       
  84.       private function onOut(param1:MouseEvent) : void
  85.       {
  86.          _backgroundHL.visible = false;
  87.          _background.visible = true;
  88.       }
  89.       
  90.       private function drawBorder() : void
  91.       {
  92.          _border = new Rect(0,0,6710886);
  93.          addChild(_border);
  94.       }
  95.       
  96.       private function drawBackground() : void
  97.       {
  98.          _backgroundHL = new GradientRectangle(0,0,[13560825,6527413]);
  99.          _backgroundHL.x = _backgroundHL.y = 1;
  100.          _backgroundHL.visible = false;
  101.          addChild(_backgroundHL);
  102.          _background = new GradientRectangle(0,0,[15921906,11776947]);
  103.          _background.x = _background.y = 1;
  104.          addChild(_background);
  105.       }
  106.       
  107.       public function set title(param1:String) : void
  108.       {
  109.          var _loc2_:TextFormat = new TextFormat();
  110.          _loc2_.color = 3355443;
  111.          _loc2_.font = new BOLD().fontName;
  112.          _loc2_.bold = true;
  113.          _loc2_.size = 14;
  114.          _label.text = param1;
  115.          _label.setTextFormat(_loc2_);
  116.          _label.width = _label.textWidth + 5;
  117.          _label.height = _label.textHeight + 5;
  118.          _border.draw(Math.round(_label.textWidth + 22),25);
  119.          _background.draw(_border.width - 2,23);
  120.          _backgroundHL.draw(_border.width - 2,23);
  121.          _label.x = _background.width / 2 - _label.textWidth / 2 - 2;
  122.          _label.y = _background.height / 2 - _label.textHeight / 2;
  123.          _overlay.draw(_border.width,_border.height);
  124.       }
  125.       
  126.       private function addOverlay() : void
  127.       {
  128.          _overlay = new Rect(_border.width,_border.height,6710886,0,false,0);
  129.          addChild(_overlay);
  130.       }
  131.    }
  132. }
  133.  
  134.