Variables and color in as3
For my flash animation I made a bouncing ball. I wanted to make the ball change color each time it was clicked and “dropped.” In order to do this I used a variable.
In actionscript, a variable is something that you call upon when you want to change the object you’re working with. First, you have to write out a variable and call it something. My variable will be called c.
You write variables like this: var (insert name here)
Example: var c
In order to use this variable I had to link it with something I wanted the ball to do. I could use variables to assign any sort of data to my ball, but I chose to change its color. The way to do this is to assign my variable to color transform.
Then, all you have to do is write
var c:ColorTransform = new ColorTransform();
This is how a variable is assigned to color transform. In the second line, I simply picked the color I wanted my ball to be using its hex number. Each time I added an event to my ball, I called up this variable by copying varc:ColorTransform and in the second line, I was able to change the color depending on the event.