How to Change the Tint on ActionScript

With AS3 statements, a tint --- a lighter or darker shade of a color --- can be used to change the color of graphics and photographs in your Flash movie as it plays (dynamic). AS3 has a set of statements, or methods, that allow you to change the tint of any photo or object placed in a flash movie. The most basic of these is the setTint method, which is used to set the color of the object and the tint level of that color.

Things You'll Need

  • Adobe Flash Professional (CS3, CS4 or CS5)
Show More

Instructions

  1. Setting Up

    • 1

      Select the "Properties" option from the "Window" menu to display the "Properties" panel --- a dialog box used to change characteristics of a selected object on the Flash stage, such as a graphic.

    • 2

      Select the "Import" menu option from the "File" menu, then select the "Import to Stage" option.

    • 3

      Select a graphic file from the directory list that appears (use the graphic file named "fashionmodel.jpg" for this example.) Click the "Open" button to import the graphic image to the Flash stage.

    • 4

      Click on the graphic image of the file and scale its size with values set in the "width" and "height" text boxes in the "properties" panel.

    • 5

      Select the "Convert to Symbol" option from the "Modify" menu on the main Flash menu bar. Check the "Export for ActionScript" box in the "Symbol" dialog box that appears. Click the "OK" button.

    • 6

      Type in the instance name "tintBox" in the "instance name" textbox within the "properties" panel.

    Entering the Tint Code

    • 7

      Select the "Actions" option from the "Window" menu to open the AS3 (ActionScript) program editor.

    • 8

      Type the AS3 import code into the first line of the ActionScript program editor to import the motion color package "fl.motion.Color." Use the AS3 program statement "import fl.motion.Color;" to import this package.

    • 9

      Type the AS3 code into the next line of the editor to create a color object called "tintColor1," Type the AS3 statement as "var tintColor1:Color=new Color();" for this example.

    • 10

      Type the tint code to assign both the color and the color tint to the tintColor1 color object, into the next line of the Action's editor. Use the hexadecimal RBG (Red, Blue, Green) code for the color red (0xff000000,) and a tint multiplier of 0.5 for the parameters in the setTint method. Use the AS3 statement "tintColor1.setTint(0xff0000, 0.5);" for this example.

    • 11

      Type the transform statement in the next line of the editor to attach the color and the color tint (the tintColor1 object) to the tintBox object on the stage. Use the AS3 statement "tintBox.transform.colorTransform=tintColor1;" for this example.

    • 12

      Review your code, as listed below, for syntax and functional correctness before you compile it and test it.

      import fl.motion.Color;

      var tintColor1:Color=new Color();

      tintColor1.setTint(0xff0000, 0.5);

      tintbox.transform.colorTransform=tintColor1;

    • 13

      Click the "Syntax Checker" icon --- a large, blue check mark at the top of the "Actions" editor --- to check the syntax of the code you entered with the ActionScript compiler. Correct any syntax errors the ActionScript compiler reports.

    • 14

      Select "Test Movie" from the "Control" menu on the main Flash menu bar. Observe that the graphic or photograph you imported on the stage is now tinted with a shade of red.

Learnify Hub © www.0685.com All Rights Reserved