- 39
- Posts
- 11
- Years
- Seen Jul 25, 2014
I'm making a dress-up game where you have the option to use a hue, brightness and saturation slider to change the color of your character's hair and clothes.
I recently learned how to make Actionscript 3 Classes and decided to use one for my game. Here is what my code looks like so far:
If you want to get a better picture of what I'm doing, follow a link to the beta version of my game: https://joy-ling.site88.net/trainercreator2.html
Basically, the sliders are in the second frame of the Movie Clip hairWindow1. I want to be able to change the color of the Movie Clip maleBodyHairFront, which is on the main timeline. maleBodyHairFront has multiple frames inside it, which are all labelled. I also have multiple layers in maleBodyHairFront. One layer is for the outline, another is for the color of the hair (which are movie clips), another is for the colors of the hats (also movieclips), etc. When I test the scene, no errors occur, however, I am unable to change the color of the hair. The rest of my code is inside the timeline.
What is wrong and how can I fix my problem?
I recently learned how to make Actionscript 3 Classes and decided to use one for my game. Here is what my code looks like so far:
Code:
package
{
import flash.display.MovieClip;
import fl.events.SliderEvent;
import flash.geom.ColorTransform;
import fl.motion.AdjustColor;
import flash.filters.ColorMatrixFilter;
public class Main extends MovieClip
{
private var colorTransform:ColorTransform=new ColorTransform();
private var color:AdjustColor=new AdjustColor();
private var filter:ColorMatrixFilter;
private var hairRoot=MovieClip(root).maleBodyHairFront;
public final function Main():void
{
color.brightness=0;
color.contrast=0;
color.hue=0;
color.saturation=0;
addListeners();
}
private final function addListeners():void
{
hairWindow1.brightSlider.addEventListener(SliderEvent.CHANGE, updateBrightness);
hairWindow1.hueSlider.addEventListener(SliderEvent.CHANGE, updateHue);
hairWindow1.satSlider.addEventListener(SliderEvent.CHANGE, updateSaturation);
}
private final function updateBrightness(e:SliderEvent):void
{
color.brightness=e.target.value;
update();
}
private final function updateHue(e:SliderEvent):void
{
color.hue=e.target.value;
update();
}
private final function updateSaturation(e:SliderEvent):void
{
color.saturation=e.target.value;
update();
}
private function update():void
{
filter = new ColorMatrixFilter(color.CalculateFinalFlatArray());
switch(hairRoot.currentFrame)
{
case 1:hairRoot.maleBodyHairFrontColor1.filters = [filter];break;
case 2:hairRoot.maleBodyHairFrontColor2.filters = [filter];break;
case 3:hairRoot.maleBodyHairFrontColor3.filters = [filter];break;
case 4:hairRoot.maleBodyHairFrontColor4.filters = [filter];break;
case 5:hairRoot.maleBodyHairFrontColor5.filters = [filter];break;
case 6:hairRoot.maleBodyHairFrontColor6.filters = [filter];break;
case 7:hairRoot.maleBodyHairFrontColor7.filters = [filter];break;
case 8:hairRoot.maleBodyHairFrontColor8.filters = [filter];break;
case 9:hairRoot.maleBodyHairFrontColor9.filters = [filter];break;
case 10:hairRoot.maleBodyHairFrontColor10.filters = [filter];break;
case 11:hairRoot.maleBodyHairFrontColor11.filters = [filter];break;
case 12:hairRoot.maleBodyHairFrontColor12.filters = [filter];break;
case 13:hairRoot.maleBodyHairFrontColor13.filters = [filter];break;
case 14:hairRoot.maleBodyHairFrontColor14.filters = [filter];break;
case 15:hairRoot.maleBodyHairFrontColor15.filters = [filter];break;
case 16:hairRoot.maleBodyHairFrontColor16.filters = [filter];break;
}
}
}
If you want to get a better picture of what I'm doing, follow a link to the beta version of my game: https://joy-ling.site88.net/trainercreator2.html
Basically, the sliders are in the second frame of the Movie Clip hairWindow1. I want to be able to change the color of the Movie Clip maleBodyHairFront, which is on the main timeline. maleBodyHairFront has multiple frames inside it, which are all labelled. I also have multiple layers in maleBodyHairFront. One layer is for the outline, another is for the color of the hair (which are movie clips), another is for the colors of the hats (also movieclips), etc. When I test the scene, no errors occur, however, I am unable to change the color of the hair. The rest of my code is inside the timeline.
What is wrong and how can I fix my problem?