Tutorial Applying filters using Actionscript 3 in Flash CS3

This tutorial will teach you how to apply filters using the Actionscript 3 programming language in Flash CS3 Filters can also be applied via the properties panel in the user interface of the the Flash application and were introduced in version 8 of the software. Using filters via your code as with every thing else gives you a much more precise control over them. The tutorial requires that you have a copy of Flash CS3 and have basic understanding of Actionscript 3 classes (which you can ascertain form our recent tutorials).

 

Your Ad Here

 

Open a new .fla document and save it as FiltersExample then open a new .as file and do the same to save it as FiltersExample. This is just to keep everything simple and together.

Then make sure you set the document class to FiltersExample this is so the code runs along with the Flash player at runtime any class.

 

Now to get started on the code

// first off we set up the package for all our code for this class to be written into
package{
   
    //The i added the relevant import statments of the classes that
    //i will require within this class during runtime. Note the DropShadowFilter class
    // was imported so that i can acces all of its functionality to be used within my code.
    import flash.display.MovieClip

    import flash.filters.DropShadowFilter
   
    // I set teh class name exactly the same as the .as file name this is common practice
    // when writing classes and ensures that class is properly loaded when required
    public class FiltersExample extends MovieClip{
       
    // I then crated 2 variables one for the box shape thats going to be
    // the rectangular shape to be drawn onto the stage using code form
    // the graphics class.
        var box:MovieClip = new MovieClip();

 

    //The other variable is for the DropShadowFilter

    //Note at the when the new filter is declared you can set the following settings

    //shown within the images. In this tutorial we only need to set the first 7

    //Note the settings already have a default value and anything you set will be added to

    //each default value
        var dropShadow:DropShadowFilter = new DropShadowFilter(6, 45, 0xCCCCCC, 0.9, 2, 2, 0.8);

 

 

 

   //Here i set the constructor function to draw out a light grey rectangle
    //Then added it on to the stage using addChild()
    //Then set dropshadow to be added to the box at runtime as a Array

        public function FiltersExample () {

    

            box.graphics.beginFill (0xCCCCCC);

            box.graphics.drawRect(200, 200, 100, 60)

            box.graphics.endFill();

            addChild(box);

            box.filters = [dropShadow]

           

        }

    }

}



//There are a ton of other filters for you to play around with and learn
//id suggest using the help files to check the parameters of each one
//all the other filters will work the same as this one
//the first four parameters of any filter will be the same.

 

you can add other parameters outside of the DropShadowFilter itself  here i set the strength of the drop shadow

public function FiltersExample () {

         

            dropShadow.strength = 10;

            box.graphics.beginFill (0xCCCCCC);

            box.graphics.drawRect(200, 200, 100, 60)

            box.graphics.endFill();

            addChild(box);

            box.filters = [dropShadow]

           

        }

    }

}


And then a knock out settings that you see in the filters pannel in the user interface of Flash

public function FiltersExample () {
            dropShadow.knockout = true;
            dropShadow.strength = 10;
            box.graphics.beginFill (0xCCCCCC);
            box.graphics.drawRect(200, 200, 100, 60)
            box.graphics.endFill();
            addChild(box);
            box.filters = [dropShadow]
           
        }
    }
}


Please subscribe to our feed, request or submit a tutorial and dont forget to comment

If you enjoyed this post, make sure you subscribe to my RSS feed

!

Comments

Leave a Reply




  • Sites We Like


  • UK Life Insurance Quotes
    Life Quotes
    Illness Insurance
    Contents Insurance
    Web Site
    Your Ad Here
    Secured Loans

    Compare secured loans to find the perfect deal for you!

    www.accepted.co.uk

    Matched.co.uk