简体   繁体   中英

Get flex component id using Mouse event action

In flex application how to get the ID of specific display component using mouse event. For example if I want to get the ID of a button it should be displayed when I click the button

do it with event.currentTarget.id like this :

<?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">

    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            protected function niceButton_clickHandler(event:MouseEvent):void
            {
                Alert.show(" the button id is: "+event.currentTarget.id)

            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:HGroup width="100%" height="100%" verticalAlign="middle" horizontalAlign="center">
        <s:Button id="niceButton" label="click me" click="niceButton_clickHandler(event)" />
    </s:HGroup>
</s:Application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM