home *** CD-ROM | disk | FTP | other *** search
- package com.simianlogic
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.text.TextFormat;
-
- public class ezButton extends Sprite
- {
-
-
- private var _label:String = "";
-
- public var active:Boolean = true;
-
- public var labelText:TextField;
-
- public var eventString:String;
-
- public var h:int;
-
- public var w:int;
-
- public var click:Sprite;
-
- public var over:Sprite;
-
- public var under:Sprite;
-
- public function ezButton(param1:String, param2:String, param3:int, param4:int)
- {
- var _loc5_:TextFormat = null;
- active = true;
- _label = "";
- super();
- w = param3;
- h = param4;
- eventString = param2;
- (_loc5_ = new TextFormat()).font = "Arial";
- _loc5_.color = 16777215;
- _loc5_.size = 16;
- under = new Sprite();
- under.graphics.beginFill(0);
- under.graphics.drawRect(0,0,w,h);
- under.graphics.endFill();
- under.graphics.beginFill(5592405);
- under.graphics.drawRect(1,1,w - 2,h - 2);
- under.graphics.endFill();
- under.buttonMode = true;
- addChild(under);
- over = new Sprite();
- over.graphics.beginFill(3355443);
- over.graphics.drawRect(1,1,w - 2,h - 2);
- over.graphics.endFill();
- over.buttonMode = true;
- under.addChild(over);
- over.visible = false;
- click = new Sprite();
- click.graphics.beginFill(0);
- click.graphics.drawRect(0,0,w,h);
- click.graphics.endFill();
- click.buttonMode = true;
- under.addChild(click);
- click.visible = false;
- labelText = new TextField();
- labelText.defaultTextFormat = _loc5_;
- labelText.selectable = false;
- labelText.y = (h - 20) / 2;
- labelText.height = 20;
- under.addChild(labelText);
- label = param1;
- under.mouseChildren = false;
- under.addEventListener(MouseEvent.ROLL_OVER,rollOver);
- under.addEventListener(MouseEvent.ROLL_OUT,rollOut);
- under.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
- under.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
- under.addEventListener(MouseEvent.CLICK,handleClick);
- }
-
- public function rollOver(param1:MouseEvent) : void
- {
- if(!active)
- {
- return;
- }
- dispatchEvent(new Event("sound_rollover",true));
- over.visible = true;
- }
-
- public function mouseUp(param1:MouseEvent) : void
- {
- if(!active)
- {
- return;
- }
- click.visible = false;
- }
-
- public function get label() : String
- {
- return _label;
- }
-
- public function handleClick(param1:MouseEvent) : void
- {
- if(!active)
- {
- return;
- }
- dispatchEvent(new Event("button_" + eventString));
- }
-
- public function rollOut(param1:MouseEvent) : void
- {
- if(!active)
- {
- return;
- }
- over.visible = false;
- click.visible = false;
- }
-
- public function set label(param1:String) : void
- {
- _label = param1;
- labelText.text = label;
- labelText.x = w / 2 - labelText.textWidth / 2;
- labelText.width = labelText.textWidth + 10;
- }
-
- public function mouseDown(param1:MouseEvent) : void
- {
- if(!active)
- {
- return;
- }
- click.visible = true;
- }
- }
- }
-