按钮监听事件

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="applicationCreationCompleteHandler(event)" minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            
            public function applicationCreationCompleteHandler(event:FlexEvent):void
            {
                this.bu.addEventListener(MouseEvent.CLICK, onClick);
                var ar:ArrayCollection = new ArrayCollection([{"label":"dog", "name":"gou"}, {"label":"cat", "name":"mao"}]);
                this.ddl.dataProvider = ar;
                var len:int = this.ddl.dataProvider.length;
            }
            private function onClick(event:MouseEvent):void {
                var obj:Object = this.ddl.selectedItem;
                Alert.show("|" + obj + "|");
                Alert.show(obj.label, "prompt");
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:VGroup>
        <s:ComboBox id="ddl"/>
        <s:Button id="bu" label="Press it"/>
    </s:VGroup>
</s:Application>

 

posted @ 2013-09-10 19:03  High阔天空  阅读(208)  评论(0)    收藏  举报