We’ll create a Class that will take care of the whole effect. When you call the class, you’ll be able to change the number of lights, color, alpha, size, direction, speed and the quality of the Blur filter. In this way it’s possible to achieve many different results when using it. Also, you can use any background you want.

Here we import the Classes that we’ll use, remember that the word next to “package” is the name of the folder where our Class is located.

Step 7: Extending the Class

//We need to extend the class so we can use the addChild() method.
public class Lights extends MovieClip
{

Extending the MovieClip class will allow our class to inherit all of the methods, properties and functions that the MovieClip has, in this case we use it to get access to the addChild() method.

Step 8: The Variables

Although they have pretty much self explanatory names I’ll add short comments on each var to make sure it’s clear. They get their values from the parameters of the Main function.

private var lightsNumber:int; //The number of Lights on Stage
private var xSpeed:int; //The horizontal speed the Lights have
private var ySpeed:int; //Vertical Speed
private var lightsDir:String; //Direction the Lights are going, this can be Up, Down, Left or Right
private var areaW:int; //The width of the area where the effect will take place
private var areaH:int; //Height
private var lights:Array = new Array(); //This array will store all the Lights MovieClips so we can use them outside the For where we are going to create them.

Here we use a for to get access to all the Lights in the Array, then check the direction variable to determine where to move the Lights. Depending on the direction we add the listener to the corresponding function.

Step 17: Move Functions

This next section may seem a little complicated, but it’s easier than you think. Basically, it moves the Light depending on the speed calculated in the Main function, then checks if the Light has “left” the Area of the effect. If that is the case, it sets a random position contrary to the direction the Light is heading.