Core Objects
Color object
You learned in basic Flash course how to change easily the transparency and adjust color tints of the instance. It may be done easily through the Properties Inspector.
It's possible also to change the color on demand programmatically. Code is rather tricky, but when you do it once it will be a good example to implement. Colors are kept in a special object named Color, which like Date object has methods to set and get color.
- Find in your libraries or create any colorful symbol. It may be done from vector drawings or from imported image. Give it an instance name. In our example it's flower
- Make eight input texts and assign each of it a variable in Properties Inspector In our example those variables are r1, r2, g1, g2, b1,b2, a1, a1 . You will enter in these text boxes values for percentage and offset of Red, Green, Blue and Alpha properties for the Color object. You may enter default values.
- Make a button and add the following code to it's event handler
on(release) { thecolor = new Color(flower); thecolorTransform = new Object(); thecolorTransform = { ra: r1, rb: r2, ga: g1, gb: g2, ba: b1, bb: b2, aa: a1, ab: a2}; thecolor.setTransform(thecolorTransform); }In this code we created a new color object and assign it to the instance of movie symbol on the stage. Then we created new generic object to keep information about color transformation and initialize the value of all color parameters to the values of our text variables.Then we pass this information as a parameter to the Color's setTransform method.
- Experiment with values of all parameters. If you wish you may return to the “Drag and Drop” lesson and borrow sliders from it. By moving sliders you may reassign the color value for the object….