AS3 colorTransform over multiple frames?
- by user359519
(Flash Professional, AS3)
I'm working on a custom avatar system where you can select various festures and colors. For example, I have 10 hairstyles, and a colorPicker to change the color.
mc_myAvatar has 10 frames. Each frame has a movieclip of a different hairstyle (HairStyle1, HairStyle2, etc.) Here's my code:
var hairColor:ColorTransform;
hairColor = mc_myAvatar.hair.colorLayer.transform.colorTransform;
hairColor.color = 0xCCCC00;
mc_myAvatar.hair.colorLayer.transform.colorTransform = hairColor;
This correctly changes the initial color. I have a "nextHair" button to advance mc_myAvatar.hair to the next frame. When I click the button, I get an error message saying that I have a null object reference. I added a trace, and mc_myAvatar.hair.colorLayer is null on frame 2. Why??? I've clearly named HairStyle2 as "colorLayer" in frame 2.
I think the problem is related to me using the same name for different classes/movieclips, but I don't know how to fix the problem...
I added a square movieclip below my hairStyle movieclips, named the square "colorLevel", and deleted the name from my hairStyle clips. When I click the next button, the square correctly maintains the color from frame to frame. However, having a square doesn't do me much good. :(
I tried converting the hairStyle layer to a mask. Doing this, however, results in yet another "null object" error - mc_myAvatar.hair.colorLayer is null after frame 1. I even tried "spanning" my colorLevel across all frames (no keyframes), thinking that this would give me just one movieclip to work with. No luck. Same error!
What's going on, here? Why am I getting these null objects, when they are clearly defined in my movieclip?
I'm also open to suggestions on a better way to do multiple frames and colors.