0

How to show different images for a single button?

It should show different images when the mouse pointer is over the button and out of the button.

  • Is this you? http://stackoverflow.com/users/702166/naveen If so, why did you create a new account. If not; I'm not sure what you're asking. Do you want to show multiple images on a single button? Or use the same class, but change the image displayed? What did you try? Why didn't it work? – JeffryHouser May 07 '11 at 20:19
  • The original question has the goal described, I don't know why @Michael Petrotta removed it. The task would be to change the icon of the button on mouse over. – rekaszeru May 07 '11 at 20:29
  • 1
    @rekaszeru: I didn't remove it; our two edits stepped over each other. Thanks for letting me know; I've added it back in. – Michael Petrotta May 07 '11 at 20:30

3 Answers3

1

<mx:Button label="test" downIcon="@Embed('assets/downIcon.png')" upIcon="@Embed('assets/upIcon.png')" />

see livedocs

xavierzhao
  • 780
  • 9
  • 18
0

I don't think there is a easy way to do it. Up to know i have chosen one of the following: 1. either write your own object, where you set event handlers to swap the image or 2. make a flash with bubbling event, and embed/load it in flex, where you catch the event (communicating between a swf from flash and flex is quite a pain, so events seem to do it)

I can provide code if you are interested in any of those two methods

UPDATE:

here's the code to the easiest way. Just add the two images:

 package {

 import flash.display.MovieClip;
 import flash.display.Sprite;
 import flash.events.MouseEvent;

   public class Test extends Sprite {

    [Embed(source="image1.png")]
    private var Image1:Class;
    [Embed(source="image2.png")]
    private var Image2:Class;


  public function Test() {
        var theHolderMC:MovieClip = new MovieClip();
        addChild(theHolderMC);

        theHolderMC.addChild(new Image2());
        theHolderMC.addChild(new Image1());

        theHolderMC.addEventListener(MouseEvent.CLICK, swap)
   }

   private function swap(e:MouseEvent):void{
        var holder:MovieClip = MovieClip(e.target);
        holder.swapChildren(holder.getChildAt(0), holder.getChildAt(1));
        // or alternatively, you can make them .visible=false or any other way you want. 
   }


}
}
mgPePe
  • 5,677
  • 12
  • 52
  • 85
  • thanks for your reply. Can you provide me the code.Here i am using flex3.Here i want to show different image when the mouse pointer is over the button and out side of the button. – user737830 May 08 '11 at 17:59
  • Can you provide me main mxml file.Whether this sol is for showing different images when the mouse pointer is over the button and out of the button? – user737830 May 09 '11 at 06:55
0

The method you choose for this task depends on your exact circumstance. The simplest way of implementing mouseover buttons doesn't involve any code; within Flash you simply define a mouseover image in the button symbol.

jhocking
  • 5,527
  • 1
  • 24
  • 38