Adding Glow Filter to Component

I got one requirement where I will draw one custom component and it should glow when we mouse hover it and remove glow when move the mouse out. This is a simple thing, though I am putting this so that you can save time. ūüôā

First we need to write a function which will be triggered on both mouse hover and mouse out of the component. Obviously it will accept one MouseEvent. Inside that we need to create one GlowFilter and add this filter to the component. Set the properties for the flow filter such as color, alpha and quality. On mouse out am removing all the filters. This will work for me since I do not have any other filters for the component. If you have other filters, then iterate through the filters and remove only the glow filter. The function will look like below :

private function highLightCircle(event:MouseEvent):void{
            var glowFilter: GlowFilter = new GlowFilter();
            var circ:Object = event.currentTarget;
            if(circ.filters.length == 0){  
                glowFilter.color = 0xFFFFFF;
                glowFilter.alpha = 1;
                glowFilter.blurX = 10;
                glowFilter.blurY = 10;
                glowFilter.quality = BitmapFilterQuality.HIGH;
                circ.filters = [glowFilter];
            }else{
                circ.filters = null;
    }
}

Now we need to call this on mouse over and mouse out. Just add the event listeners to the component object on which you need to apply the filter like below.

circle.addEventListener(MouseEvent.ROLL_OVER, highLightCircle);
circle.addEventListener(MouseEvent.ROLL_OUT, highLightCircle);

Thats all guys. Flex your life. Happy Coding. ūüôā

Advertisements

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: