Sunday, February 13, 2011

Object Selection sample code


Object Selection

stop();

//Tutorial for this code was found on //www.atomicrobotdesign.com/blog/flash/animate-the-glow-filter-in-as3
//accessed on January 31, 2011

//We have to import the filters so we can use them
import flash.filters.*;



//This creates a new GlowFilter that we can then assign to a movieclip on the stage
var gasulGlow:GlowFilter = new GlowFilter();

//The color of the GlowFilter
gasulGlow.color = 0x138613;

//The size of the filter on the x-axis
gasulGlow.blurX = 50;

//The size of the filter on the y-axis, these don't have to be the same
gasulGlow.blurY = 50;


//Setting the alpha of our filter to zero to start off with

gasulGlow.alpha = 0;

//Assigning the GlowFilter to the movieclip

gasul.filters = [gasulGlow];


//This will tell our filter when to turn on and off

var glow:Boolean = false;



//Our listeners

gasul.addEventListener(MouseEvent.MOUSE_OVER, addGlow);
gasul.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);
gasul.addEventListener(MouseEvent.MOUSE_UP, playFrame2);
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

{
  
glow = true;
}



//This turns off the glow when the mouse cursor leaves the movieclip

function removeGlow(e:MouseEvent):void
{
 
glow = false;  
}



//This checks the status of glow and turns on and off our glow
function increaseGlow(e:Event):void

{
   
if(glow == true)
    {
       

//If glow = true, then it will increase the alpha of gasulGlow by 0.02 each frame. This number can be changed to anything between 0 and 1 depending on how fast
you want the glow to appear
        gasulGlow.alpha = gasulGlow.alpha + 0.02;
    }
    else if(glow == false)
    {
       

//If glow is false, then it will decrease the alpha by 0.02
       
gasulGlow.alpha = gasulGlow.alpha - 0.02;
    }
   

//Assigns the glow filter with the new alpha to gasul
   
gasul.filters = [gasulGlow];
}


//This plays frame 2 once movieclip is clicked upon

function playFrame2 (e:MouseEvent):void
           
{
removeEventListener(Event.ENTER_FRAME, increaseGlow);
                       
gotoAndPlay(2);
           
}

No comments:

Post a Comment