跟我StepByStep学FLEX教程 - Demo5之事件Event

2012-03-23
浏览
导读:Demo的运行效果: 源码如下: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml layout=absolute creationComplete=

Demo的运行效果:

源码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="creationBtnHandler (event)">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;

   private function test1ClickHandler(e:MouseEvent):void {
     mxmlRegInp.text= "MXML 中注册事件";
    Alert.show (e.currentTarget.toString());
   }

    private function creationBtnHandler(e:Event):void {
     eventTes3Btn.addEventListener(MouseEvent.CLICK, test3ClickHandler);
   }

   private function test3ClickHandler (e:Event):void {
    mxmlRegInp.text= "ActionScript 注册 事件监听器";
   }
  ]]>
  </mx:Script>

 <mx:Button x="59" y="32" label="MXML 中注册事件" id="eventTes1Btn" click="test1ClickHandler(event)" fontSize="12" width="140"/>
  <mx:Button x="207" y="32" label="MXML 定义 中创建线上事件" id="eventTes2Btn" click="mxmlRegInp.text='MXML 定义中创建线上事件'" fontSize="12" width="185"/>
  <mx:TextInput x="59" y="82" id="mxmlRegInp" fontSize="12" width="333" enabled="true" color="#13E409" fontWeight="bold" fontStyle="italic" editable="false"/>
  <mx:Button x="59" y="127" label="ActionScript 注册事件监听器" fontSize="12" width="333" id="eventTes3Btn"/>

</mx:Application>

这个Demo演示了Flex的三种事件方 式,也就是按钮上写的名称:

1、MXML 中注册事件;

2、MXML 定 义中创建线上事件;

3、ActionScript 注册事件监听器;

其中第 2种方式仅供大家理解,作者不建议读者使用第2种方式在项目中实际应用,这种 方式代码生硬,不易维护。

大家可以做一下这个Demo,下一讲将对事件 event进行一些理论上的补充。

文章来源: http://wangyisong.javaeye.com/blog/373563

Flash基础教程 动画基础知识

flash as3.0 跨域的解决办法

网络相册开发(8)——Cairngorm架构浅析

Flex中PureMVC学习小结

Flex与.NET互操作(十六):FluorineFx + F