• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Question] Need Help With Actionscript 3

jcl

39
Posts
10
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:

    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: http://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?
     

    th3shark

    Develops in AS3/C++
    79
    Posts
    10
    Years
  • First of all, this looks very nice! I wish I was as good at vector art as you.

    I'm actually having a hard time finding instances where changing hair color doesn't work. For example, the style on the bottom right of the second page of the front hair lets me change the hat color, but not the hair color. Perhaps you forgot to put a label in a frame of that MovieClip?

    But that seems like a relatively minor issue. Can you be more descriptive in what's wrong?

    Also for nicer code, change update() to this:

    private function update():void {
    filter = new ColorMatrixFilter(color.CalculateFinalFlatArray());
    for (var i:int=1;i<=16;i++){
    hairRoot["maleBodyHairFrontColor"+String(i)].filters = [filter];
    //Why is filter in brackets anyway?​
    }​
    }
     

    jcl

    39
    Posts
    10
    Years
    • Seen Jul 25, 2014
    Thanks a million for replying -- you're the first person that has tried to help me. xD

    I have provided screenshots hoping that they will help explain my situation.

    This is my main timeline.


    This is what is inside the movieclip "hairWindow1"


    This is what is inside the movieclip "maleBodyHairFront"


    I have managed to get the color sliders to work on a separate FLA file, however, the file was very simple and only had the sliders convert the color of a single movieclip. In this situation, I want the sliders in frame 2 of "hairWindow1" to manipulate "maleBodyHairFront" and all of the movieclips inside of it.

    I have tried to insert your cleaner code but to no avail. I have also tried a myriad of other possible solutions but nothing seems to work. If this is not sufficient enough information for you then I can send you the source files.
     
    Back
    Top