-
/**
-
* @author Matt Przybylski [http://www.reintroducing.com]
-
* @version 1.0
-
*/
-
-
package com.reintroducing.menusystem.ui
-
{
-
import flash.display.MovieClip;
-
import flash.events.MouseEvent;
-
import flash.net.URLRequest;
-
import flash.net.navigateToURL;
-
import flash.text.TextField;
-
-
import com.reintroducing.menusystem.events.MenuButtonEvent;
-
-
import gs.TweenLite;
-
-
public class MenuButton extends MovieClip
-
{
-
//- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------
-
-
private var _id:int;
-
private var _url:String;
-
-
//- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------
-
-
public static const DEFAULT_NAME:String = "com.reintroducing.menusystem.ui.MenuButton";
-
-
// instances
-
public var bg_mc:MovieClip;
-
public var title_txt:TextField;
-
-
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
-
-
public function MenuButton()
-
{
-
super();
-
-
this.init();
-
}
-
-
//- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------
-
-
private function init():void
-
{
-
this.buttonMode = true;
-
this.mouseChildren = false;
-
this.setEnabled();
-
}
-
-
/**
-
* Resets the button to its original state.
-
*/
-
private function reset():void
-
{
-
TweenLite.to(this.bg_mc, .25, {mcColor: 0x999999});
-
}
-
-
/**
-
* Executed when you mouse over the button.
-
*/
-
private function doMouseOver($evt:MouseEvent):void
-
{
-
TweenLite.to(this.bg_mc, .25, {mcColor: 0x333333});
-
}
-
-
/**
-
* Executed when you mouse out of the button.
-
*/
-
private function doMouseOut($evt:MouseEvent):void
-
{
-
this.reset();
-
}
-
-
/**
-
* Executed on release of the button.
-
*/
-
private function doClick($evt:MouseEvent):void
-
{
-
navigateToURL(new URLRequest(this._url));
-
-
this.dispatchEvent(new MenuButtonEvent(MenuButtonEvent.CLICKED, {id: this._id}));
-
}
-
-
//- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------
-
-
/**
-
* Assigns the button a name and ID for later retrieval through events.
-
*/
-
public function create($name:String, $title:String, $id:int, $url:String):void
-
{
-
this.name = $name;
-
this._id = $id;
-
this.title_txt.text = $title;
-
this._url = $url;
-
}
-
-
/**
-
* Allows the button to be clickable and functional.
-
*/
-
public function setEnabled():void
-
{
-
this.enabled = true;
-
this.reset();
-
-
this.addEventListener(MouseEvent.MOUSE_OVER, doMouseOver);
-
this.addEventListener(MouseEvent.MOUSE_OUT, doMouseOut);
-
this.addEventListener(MouseEvent.CLICK, doClick);
-
}
-
-
/**
-
* Disables the button and kills its events.
-
*/
-
public function setDisabled():void
-
{
-
this.enabled = false;
-
-
this.removeEventListener(MouseEvent.MOUSE_OVER, doMouseOver);
-
this.removeEventListener(MouseEvent.MOUSE_OUT, doMouseOut);
-
this.removeEventListener(MouseEvent.CLICK, doClick);
-
}
-
-
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
-
-
-
-
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
-
-
public function get id():int
-
{
-
return this._id;
-
}
-
-
public function set id($val:int):void
-
{
-
this._id = $val;
-
}
-
-
//- HELPERS -----------------------------------------------------------------------------------------------
-
-
public override function toString():String
-
{
-
return "com.reintroducing.menusystem.ui.MenuButton";
-
}
-
-
//- END CLASS ---------------------------------------------------------------------------------------------
-
}
-
}