2009年8月23日 星期日

ActionScript3 自定義事件使用

//客制化事件物件
package customEvent
{
  import flash.events.Event;

  public class CustomEvent extends Event
  {
    //事件名稱
    static public const ATTRIBUTE_CHANGED:String = "attributeChanged";
    //建構式
    public function CustomEvent(
      type:String,
      newAttribute:Object=null, oldAttribute:Object=null,
      bubbles:Boolean=false, cancelable:Boolean=false)
    {
       super(type, bubbles, cancelable);
       this.newAttribute = newAttribute;
       this.oldAttribute = oldAttribute;
    }

    //新的屬性值

    private var _newAttribute:Object;
    public function get newAttribute():Object
    {
  return _newAttribute;
    }
    public function set newAttribute(value:Object):void
    {
     _newAttribute = value;
    }

    //舊的屬性值
    private var _oldAttribute:Object;
    public function get oldAttribute():Object
    {
  return _oldAttribute;
    }
    public function set oldAttribute(value:Object):void
    {
  _oldAttribute = value;
    }

    override public function  clone():Event
    {
    return new CustomEvent(type , newAttribute, oldAttribute , bubbles , cancelable);
    }
   }
}