AS3.0 实例学习 熟悉AS3的package,以及多个package之间的相互通信

  package todd.interactive{

  import flash.display.*;

  import flash.events.*;

  import todd.interactive.ButtonSet;

  public class DisablingButton extends MovieClip {

  var labels:Array;

  var thisParent:*;

  var thisIndex:int;

  public function DisablingButton() {

  labels = this.currentLabels;

  this.addEventListener(MouseEvent.CLICK, disableButton);

  this.addEventListener(MouseEvent.ROLL_OVER, over);

  this.addEventListener(MouseEvent.ROLL_OUT, out);

  this.addEventListener(Event.ADDED,setParent);

  }

  function disableButton(event:MouseEvent):void {

  for (var i:int = 0; i < labels.length; i++) {

  if (labels[i].name == "disable") {

  this.gotoAndPlay("disable");

  }

  }

  this.removeEventListener(MouseEvent.CLICK, disableButton);

  this.removeEventListener(MouseEvent.ROLL_OVER, over);

  this.removeEventListener(MouseEvent.ROLL_OUT, out);

  enableOthers();

  }

  function enableButton():void {

  this.addEventListener(MouseEvent.CLICK, disableButton);

  this.addEventListener(MouseEvent.ROLL_OVER, over);

  this.addEventListener(MouseEvent.ROLL_OUT, out);

  this.gotoAndStop(1);

  }

  function over(event:MouseEvent):void {

  for (var j:int = 0; j < labels.length; j++) {

  if (labels[j].name == "over") {

  this.gotoAndPlay("over");

  }

  }

  }

  function out(event:MouseEvent):void {

  for (var k:int = 0; k < labels.length; k++) {

  if (labels[k].name == "out") {

  this.gotoAndPlay("out");

  }

  }

  }

  function setParent(event:Event):void {

  if (this.parent is ButtonSet) {

  thisParent=this.parent;

  for (var w:int=0; w < thisParent.buttons.length; w++) {

  if (this == thisParent.buttons[w]) {

  thisIndex=w;

  }

  }

  }

  }

  function enableOthers():void {

  for (var z:int=0; z < thisParent.buttons.length; z++) {

  if (z != thisIndex) {

  thisParent.buttons[z].enableButton();

  }

  }

  }

  }

  }