Flex Metadata Event 使用範例

Flex 2009/07/02 09:51

1.先自定一個EVENT CLASS
package com.C_event{                   //放在SRC/com/C_event的資料夾下
 import flash.events.Event;

 public class WindowsEvent extends Event//繼承EVENT
 {
  public static const WINDOW_RESTORE_START:String="onWindowRestoreStart";//弄個常數
  public function WindowsEvent(type:String)
  {
   super(type);//把東西丟回EVENT
  }
 }
}

2.新增一個MXML(取名為CWindow)也放在SRC/com/C_event的資料夾下(注意![Event(name="onWindowRestoreStart",type="com.C_event.WindowsEvent")]裡的onWindowRestoreStart這個字串要和WindowsEvent 裡的WINDOW_RESTORE_START常數值一樣)

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
 width="400" height="400" minWidth="200" minHeight="200">
 <mx:Metadata>
  [Event(name="onWindowRestoreStart",type="com.C_event.WindowsEvent")]
 </mx:Metadata>
 <mx:Script>
  <![CDATA[
  private function dpWevent(e:MouseEvent):void{//若點擊視窗中的按鈕就視為觸發WINDOW_RESTORE_START這個EVENT
   var W_event:WindowsEvent=new WindowsEvent(WindowsEvent.WINDOW_RESTORE_START);
   this.dispatchEvent(W_event);

  }
   
  ]]>
 </mx:Script>
 <mx:Button x="121" y="103" label="Button" width="155" click="dpWevent(event)"/>
 
</mx:Canvas>

3.在產生一個MXML(主程式)放在 src的資叫夾中去引用CWindow這個TAG

<?xml version="1.0"?>
<!-- charts/CSSFillsArrayExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:Comp="com.C_event.*">
  <mx:Script>
   <![CDATA[
   import com.C_event.WindowsEvent;
    private function onEvent(e:WindowsEvent):void{
     trace(e.currentTarget)
    }
   ]]>
  </mx:Script>
  <Comp:CWindow onWindowRestoreStart="onEvent(event)">
   
  </Comp:CWindow>
</mx:Application>

top

Trackback Address :: http://diary.tw/allenliao/trackback/791

Write a comment


PREV : [1] : ... [7] : [8] : [9] : [10] : [11] : [12] : [13] : [14] : [15] : ... [80] : NEXT