Sunday, October 3, 2010

How to create Flex button with pulsing effects?

You can create simple Flex button using MXML tag or actionscript but many times you need more on real world project. You can assign some kind of animation or pulsing background to normal Flex button. But to do that you have to create the effects in Flash. Now you have to import that into Flex but do that you need to do the following

1. First create Animation.swf Flash file. It has effects you want to assign to Flex button.

2. Animation.swf contains symbol name. Now you create simple actionscript class call Assets.as


public class Assets{

[Embed(source='assets/animations/Animation.swf#square')]
public static var animation_icon:Class;

}

3. Make sure you have "square" symbol or any other name symbol in Flash file. That symbol will have animation or effects you want to assign to flex button.

4. Now in your Flex or actionscript code where you have created button assign the effects like this

button.setStyle("icon",Assets.animation_icon);

5. You can remove the effects using following
button.styleName = (any normal button style you want to see);


Now you can see the animation or effects in Flex button.

Enjoy.