www.pudn.com > videoChat.zip > ToggleButtonClass.as


#initclip  
 
function ToggleButtonClass(){ 
   this._on = false; 
   this._over = false; 
   this._enabled = true; 
} 
 
ToggleButtonClass.prototype = new MovieClip(); 
 
ToggleButtonClass.prototype.onLoad = function(){ 
  this.setToggle(this._on); 
} 
 
ToggleButtonClass.prototype.onRollOver = function(){ 
  this._over = true; 
  if (! this._enabled) return; 
  if (this._on){ 
    this.gotoAndStop("On_Over"); 
  } 
  else{ 
    this.gotoAndStop("Off_Over"); 
  } 
} 
 
ToggleButtonClass.prototype.onRollOut = function(){ 
  this._over = false; 
  if (! this._enabled) return; 
  if (this._on){ 
    this.gotoAndStop("On_Normal"); 
  } 
  else{ 
    this.gotoAndStop("Off_Normal"); 
  } 
} 
 
ToggleButtonClass.prototype.onPress = function(){ 
  if (! this._enabled) return; 
  if (this._on){ 
    this.gotoAndStop("On_Over"); 
  } 
  else{ 
    this.gotoAndStop("Off_Over"); 
  } 
  this.objectReference[this.methodName](this); 
} 
 
ToggleButtonClass.prototype.isOn = function(){ 
  return this._on; 
} 
 
ToggleButtonClass.prototype.setToggle = function(flag){ 
  this._on = ( flag )? true : false; 
  var stateName = this._on ? "On_" : "Off_"; 
  stateName += this._over ? "Over" : "Normal";  
  this.gotoAndPlay(stateName); 
} 
 
ToggleButtonClass.prototype.setClickHandler = function(methodName, objectReference){ 
   this.methodName = methodName; 
   if (objectReference != null) 
      this.objectReference = objectReference; 
   else 
      this.objectReference = this._parent; 
   if (typeof this.objectReference[this.methodName] != "function") 
     trace("WARNING: Can't find function reference for " + methodName + " on " + objectReference + "."); 
} 
 
 
#endinitclip