Wednesday 19 December 2012

glow filter effect on mouse-over in as3

1. create a movieclip with the instance name of 'robot'



import flash.filters.*;

//This creates a new GlowFilter that we can then assign to a movieclip on the stage
var robotGlow:GlowFilter = new GlowFilter();
//The color of the GlowFilter
robotGlow.color = 0x138613;
//The size of the filter on the x-axis
robotGlow.blurX = 50;
//The size of the filter on the y-axis, these don't have to be the same
robotGlow.blurY = 50;
//Setting the alpha of our filter to zero to start off with
robotGlow.alpha = 0;
//Assigning the GlowFilter to the robot movieclip
robot.filters = [robotGlow];
//This will tell our filter when to turn on and off
var glow:Boolean = false;

//Our listeners

addEventListener(Event.ENTER_FRAME, increaseGlow);

//This function sets glow to true which turns on the glow when the mouse cursor is over our movieclip
function addGlow(e:MouseEvent):void
{
    robotGlow.alpha = 100;
glow = true;
}

//This turns off the glow when the mouse cursor leaves the movieclip
function removeGlow(e:MouseEvent):void
{
    robotGlow.alpha =0;
glow = false;  
}

//This checks the status of glow and turns on and off our glow
function increaseGlow(e:Event):void
{
    robot.addEventListener(MouseEvent.MOUSE_OVER, addGlow);
robot.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);
    robot.filters = [robotGlow];
}



Out put looks like :-



No comments:

Post a Comment