Flash Education: Learn to use the ColorMatrixFilter & set the ActionScript.

Home • Members Tutorials Forum iSnapChat Contact Us 

 


Flash Tutorials

   

Color Matrix Filter with ActionScript

 

Free Flash Tutorial


Step 2    <<   Previous      Intro   1   2   3   4   5   6   7     Next   >>      

 

Step Two: The ActionScript

  1. In the Timeline insert a new Layer:
  2. Name the Layer: ActionScript
  3. Select Frame 1 of the Actionscript Layer: Frame 1
  4. Open the Actions Panel: Window > Actions (F9)
  5. If Script Assist is on, Switch it off:

    Note: With Script Assist on you cannot type in the Actions Panel. If you want to learn more about Script Assist see the tutorial on the Actions Panel

  6. Type (or paste) the following into the Actions Panel:

    // Makes the filter available to use in the Movie.
    import flash.filters.ColorMatrixFilter;

    // Defines which colors to change.
    var myMatrix:Array = [2,0,0,0,0,   /* Red */
                          0,1,0,0,0,   /* Green */
                          0,0,2,0,0,   /* Blue */
                          0,0,0,1,0 ]; /* Alpha Transparency */

    // Creates a variable with info about the Filter settings.
    var colorMatrix = new ColorMatrixFilter(myMatrix);

    // Applies the filter to the object named myObject.
    myObject.filters = [colorMatrix];

     

    Note: If you wish you can type the Matrix in a more standard format like this:

    [2,0,0,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,1,0];

    Or like this:

    [2,0,0,0,0, 0,1,0,0,0, 0,0,2,0,0, 0,0,0,1,0];

    I have spread it out into a matrix as this makes it is much easier to understand and edit. If you wish to type the code in a matrix format make sure you don't get your commas (,) and semi colons (;) mixed up. If you do you will get errors. There is only one semi colons (;) which defines the codes end of line:

    [2,0,0,0,0,   /* Red */
     0,1,0,0,0,   /* Green */
     0,0,2,0,0,   /* Blue */
     0,0,0,1,0]
    ;  /* Alpha Transparency */

    If you wish you can leave out the gray comments and white space. I only add the comments and space to make the code easier to read and edit. It could just as well be typed like this:

    [2,0,0,0,0,
     0,1,0,0,0,
     0,0,2,0,0,
     0,0,0,1,0];

     

  7. Test your Movie: Control > Test Movie (Ctrl Enter)

I hope you have found this useful. If so perhaps you could recommend this site to others and link to webwasp!

         

Step 2    <<   Previous      Intro   1   2   3   4   5   6   7     Next   >>      


33486 visitors to this page since 2 April 07 •

Phil Schulz's Facebook Profile
Webwasp is Phil Schulz's baby. You are welcome to contact me or become my Facebook friend: Click here

 Top of Page HomeMembers Tutorials Forum iSnapChat Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.