In general it is probably better, and more common, to pass the event and let the method decide what it needs from it:

<mx:Button id="IAMAButton1" label="validate" click="getHandler(event)" />

private function getHandler( event:MouseEvent ):void {
   trace(event.target.id);
}

Yours truly,
-Brian

ben gomez farrell wrote:

OK I'm still new to Flex, but as I've been playing with it all day, I think I can answer this. Your click function is coded in such a way that you've ignored the event coming coming in. Yah, "getHandler" gets called on click, but there's some more details you could get when it gets clicked.

Here's how I'd do it:
<mx:Button id="IAMAButton1" label="validate" click="getHandler(event.target.id)" />

private function getHandler( id:String ):void {
    trace(id);
}

Or you could pass in the whole target: click="getHandler(event.target)"

and get it in the getHandler(target:Button) by doing trace(target.id);

That help?
ben

macromedia flash wrote:

Hi there,

I am working on Flex and need to get the button ID in function, do you have
any ideas?


<?xml version="1.0" encoding="utf-8"?>
<!-- FLEX 2 SOLUTION -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>

    <mx:Script>
        <![CDATA[
        private function getHandler():void{
            //how to get the button ID name here => IAMAButton "x" ?
        }

        ]]>
    </mx:Script>


    <mx:Button id="IAMAButton1" label="validate" click="getHandler()" />

    <mx:Button id="IAMAButton2" label="validate" click="getHandler()" />

    <mx:Button id="IAMAButton3" label="validate" click="getHandler()" />

</mx:Application>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



--
______________________________________________________________________
Brian Lesser
Assistant Director, Application Development and Integration
Computing and Communications Services
Ryerson University
350 Victoria St.
Toronto, Ontario                   Phone: (416) 979-5000 ext. 6835
M5B 2K3                            Fax: (416) 979-5220
Office: POD??                      E-mail: [EMAIL PROTECTED]
(Enter through LB99)               Web: http://www.ryerson.ca/~blesser
______________________________________________________________________

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to