You can do this easily by setting button's toggle property to true and then changing the icon image by checking the value of button's selected property. See this example code:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" > <mx:Script> <![CDATA[ [Embed("image1.jpg")] var img1:String; [Embed("image2.jpg")] var img2:String; private function checkToggle() { if (b1.selected) b1.icon = img2; else b1.icon = img1; } ]]> </mx:Script> <mx:Button id="b1" toggle="true" label="Button1" icon="{img1}" click="checkToggle()"/> </mx:Application> -Ashish > -----Original Message----- > From: flexcoders@yahoogroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of Prasad Dhananjaya > Sent: Sunday, September 11, 2005 9:58 PM > To: FlexML > Subject: [flexcoders] How to change the button's image after click > > Hi, > > I want to change the button's image(icon image) after click. > (use this as toggle button) > I tried several ways, but failed. Can someone tell me how to do this? > > thanks > > --------------------------------------------------------------------- > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" > > <mx:Script> > <![CDATA[ > var first:String = "true"; > function changeImage() > { > if (first=="true"){ > but1.load('ob2.jpg'); > first="false"; > } > else { > but1.load('ob1.jpg'); > first="true"; > } > } > ]]> > </mx:Script> > <mx:VBox> > <mx:Button id="but1" click="changeImage()" /> > </mx:VBox> > </mx:Application> > > --------------------------------------------------------------------- > > > ------------------------ Yahoo! Groups Sponsor > --------------------~--> > Most low income households are not online. Help bridge the > digital divide today! > http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/nhFolB/TM > -------------------------------------------------------------- > ------~-> > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life. http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/