Game Development Reference
In-Depth Information
The Button Effect class
This class takes in any sprite and adds two things that provide a hint to the player
that it is clickable. Firstly, when the mouse is over the sprite, it adds a shadow filter
and removes it when the mouse leaves the bounds of the sprite. Secondly, it turns the
cursor from the normal arrow to a hand.
Note that you still need to hook up your mouse event handler to actually handle
any mouse events.
Here is a full listing of the class ButtonEffect.as :
package pulseui.util
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class ButtonEffect
{
private var m_btn:Sprite;
public function ButtonEffect(btn:Sprite) {
m_btn = btn;
m_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
m_btn.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
btn.buttonMode = true;
btn.useHandCursor = true;
}
private function mouseOver(event:Event):void {
var filters:Array = m_btn.filters;
filters.push(FilterFactory.
createFilter(FilterFactory.DROP_SHADOW_FILTER));
m_btn.filters = filters;
}
private function mouseOut(event:Event):void {
var filters:Array = m_btn.filters;
filters.splice(0, 1);
 
Search WWH ::




Custom Search