rendered paste body//!-- UTF8
import com.johannesaxner.util.IntervalTween;
import mx.events.EventDispatcher;
/**
* Navigation button class for Blodcentralen
* @author Johannes Axner <contact@johannesaxner.com>
*/
class se.jerlov.blodcentralen.NavigationButton extends MovieClip
{
/**
* Vars and functions inherited by EventDispatcher.
*/
public var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;
private var label_txt:TextField;
private var buttonContent_mc:MovieClip;
private var base_mc:MovieClip;
private var module_str:String;
private var hoverOffset_num:Number = 1;
private var hoverDuration_num:Number = 75;
private var intervalLength_num:Number = 5;
private var baseX_num:Number;
private var baseY_num:Number;
private var parent_mc:MovieClip;
private var shadow_mc:MovieClip;
public var highlight_bool:Boolean = false;
/**
* Class constructor
*/
public function NavigationButton() {}
/**
* Sets the label for the button
*
* @param param_label_str Label for button
* @return String The set label
*/
private function setLabel( param_label_str:String ):String
{
this.buttonContent_mc.label_txt.text = param_label_str;
this.buttonContent_mc.label_txt._y = -Math.round(this.buttonContent_mc.label_txt.textHeight/2);
this.buttonContent_mc.label_txt._x = -35;
return this.buttonContent_mc.label_txt.text;
}
private function setModule( param_module_str:String ):String
{
this.module_str = param_module_str;
return this.module_str;
}
public function init( param_parent_mc:MovieClip, param_label_str:String, param_module_str:String ):Void
{
this.parent_mc = param_parent_mc;
this.setLabel( param_label_str );
this.setModule( param_module_str );
this.setRollOver();
this.baseX_num = this._x;
this.baseY_num = this._y;
this.buttonContent_mc.base_mc.colorOn_mc._alpha = 0;
//this.buttonContent_mc.onRelease = mx.utils.Delegate.create( this, release );
}
private function rollOver()
{
this.highlight_bool = true;
this.parent_mc.highlightLink(this);
delete this.buttonContent_mc.onRollOver;
delete this.buttonContent_mc.onRollOut;
var base_tween:IntervalTween = new IntervalTween( this.buttonContent_mc, '_x', mx.transitions.easing.Regular.easeOut, this._x, this._x-hoverOffset_num, hoverDuration_num, intervalLength_num );
var base_tween:IntervalTween = new IntervalTween( this.buttonContent_mc.base_mc.colorOn_mc, '_alpha', mx.transitions.easing.Regular.easeOut, 0, 100, hoverDuration_num, intervalLength_num );
new IntervalTween( this.buttonContent_mc, '_y', mx.transitions.easing.Regular.easeOut, this.baseY_num, this.baseY_num-hoverOffset_num, hoverDuration_num, intervalLength_num );
base_tween.onMotionFinished = mx.utils.Delegate.create( this, setRollOut );
}
private function setRollOver()
{
this.buttonContent_mc.onRollOver = mx.utils.Delegate.create( this, rollOver );
}
private function setRollOut()
{
this.buttonContent_mc.onRollOut = mx.utils.Delegate.create( this, rollOut );
}
private function rollOut()
{
this.highlight_bool = false;
delete this.buttonContent_mc.onRollOver;
delete this.buttonContent_mc.onRollOut;
var base_tween:IntervalTween = new IntervalTween( this.buttonContent_mc, '_x', mx.transitions.easing.Regular.easeOut, this.baseX_num-hoverOffset_num, this.baseX_num, hoverDuration_num, intervalLength_num );
var base_tween:IntervalTween = new IntervalTween( this.buttonContent_mc.base_mc.colorOn_mc, '_alpha', mx.transitions.easing.Regular.easeOut, 100, 0, hoverDuration_num, intervalLength_num );
new IntervalTween( this.buttonContent_mc, '_y', mx.transitions.easing.Regular.easeOut, this.baseY_num-hoverOffset_num, this.baseY_num, hoverDuration_num, intervalLength_num );
base_tween.onMotionFinished = mx.utils.Delegate.create( this, setRollOver );
}
private function onRelease()
{
var event_obj:Object = { target:this, type:"onRelease", module_str:this.module_str };
this.dispatchEvent( event_obj );
}
}