FLEX4_Label與Button建立Click 事件判斷範例
- <?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" minWidth="955" minHeight="600"
- initialize="init()">
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <fx:Script>
- <![CDATA[
- private function init():void{
- button3.addEventListener(MouseEvent.CLICK , handleClick);
- }
- private function handleClick(event:MouseEvent):void{
- if(event.target==button2){
- label.text+='Button 2 clicked\n';
- }
- else if(event.target==button3){
- label.text+='Button 3 clicked\n';
- }
- }
- ]]>
- </fx:Script>
- <s:VGroup x="0" y="0" width="100%">
- <s:Button id="button1" x="198" y="223" label="Button 1" click="label.text+='Button 1 clicked\n'"/>
- <s:Button id="button2" x="336" y="223" label="Button 2" click="handleClick(event)"/>
- <s:Button id="button3" x="482" y="223" label="Button 3"/>
- <s:Label id="label"/>
- </s:VGroup>
- </s:Application>
初始化事件分有:initialize、creationComplete、applicationComplete
按下Button 1會顯示 Button 1,Button 2會顯示 Button 2,Button 3會顯示 Button 3,並且會累加下去。
留言
張貼留言