18 Replies Latest reply on Dec 7, 2016 9:47 AM by xCyper

    Change color

    xCyper Level 1

      Hello,

      I'm making a game in Adobe Flash Professional CS6 using Actionscript 2.0

      I've made my character (named player) and everything and now i want to add an fun easter egg.

      What is want is that when you press the keys: UP, DOWN, RIGHT, LEFT, W, A, S and D that there will be a filter added that make everything yellowish.

      I couldn't find any code to do this so i decided to make only the character yellow, this also didn't work.

      My question is if anyone knows a code to make a filter on a frame.

      My current code is:

       

      onClipEvent (enterFrame) { powerleft = 5; powerright = 10; powerupdown = 7;

      if(Key.isDown(Key.SHIFT)){

      powerright = 15;

      }

      else {

      powerright = 10;

      }

      if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.LEFT) and (Key.isDown(UP) and (Key.isDown(DOWN) and (Key.isDown(87) and (Key.isDown(65) and (Key.isDown(83) and (Key.isDown(68))))))))) {

      myColor = new Color(player);

      myColor.setRGB(0xff00ff);

      }

      if (Key.isDown(Key.RIGHT)) { this._xscale = 100; this._x += powerright; if(jumping){ this.gotoAndStop(3);

      }

      else { this.gotoAndStop(1); }

      }

      if (Key.isDown(Key.LEFT)) { this._xscale = 100; this._x -= powerleft; if(jumping){ this.gotoAndStop(3);

      }

      else { this.gotoAndStop(1); }

      }

      if (Key.isDown(Key.UP)) { this._xscale = 100; this._y -= powerupdown; if(jumping){ this.gotoAndStop(3);

      }

      else { this.gotoAndStop(1); }

      }

      if (Key.isDown(Key.DOWN)) { this._xscale = 100; this._y += powerupdown; if(jumping){ this.gotoAndStop(3);

      }

      else { this.gotoAndStop(1); }

      }

      if (!Key.isDown(Key.DOWN) and (!Key.isDown(Key.UP) and (!Key.isDown(Key.LEFT) and (!Key.isDown(Key.RIGHT))))) { this.gotoAndStop(2); }

      }

      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.wall1)) { this._x +=25; }

      }

      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.wall2)) { this._x -=25; }

      }

      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.ceiling)) { this._y +=25; }

      }

      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.ground)) { this._y -=25; }

      }

       

       

       

      It's all about the

       

      if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.LEFT) and (Key.isDown(UP) and (Key.isDown(DOWN) and (Key.isDown(87) and (Key.isDown(65) and (Key.isDown(83) and (Key.isDown(68))))))))) {

      myColor = new Color(player);

      myColor.setRGB(0xff00ff);

      }

       

      part.

      Can anyone help me?

      Thanks for your advice.

        • 1. Re: Change color
          kglad Adobe Community Professional & MVP

          use:

           

          import flash.geom.ColorTransform;

          var ct:ColorTransform=player.transform.colorTransform;

          .

          .

           

           

          if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.LEFT) and (Key.isDown(UP) and (Key.isDown(DOWN) and (Key.isDown(87) and (Key.isDown(65) and (Key.isDown(83) and (Key.isDown(68))))))))) {

          ct.rgb=0xff00ff;
          player.transform.colorTransform=ct;

          }

           

          1 person found this helpful
          • 2. Re: Change color
            xCyper Level 1

            Thank you for your respond, i tried putting

            import flash.geom.ColorTransform;

            var ct:ColorTransform=player.transform.colorTransform;

            in my code and updated my code to what you said, unfortunately this didn't work

            maybe i misunderstood what you meant with

            use:

             

            import flash.geom.ColorTransform;

            var ct:ColorTransform=player.transform.colorTransform;

             

            but the color didn't change when i pressed the keys.

            • 3. Re: Change color
              kglad Adobe Community Professional & MVP

              because you're attaching code to objects (which is a bad idea), you probably have a scope problem.

               

              you really shouldn't be using any code attached to objects like onClipEvents. but if you're going to continue doing that, this would add to your mess, but probably work if you add that import line correctly:

               

              onClipEvent (enterFrame) { powerleft = 5; powerright = 10; powerupdown = 7;

              if(Key.isDown(Key.SHIFT)){

              powerright = 15;

              }

              else {

              powerright = 10;

              }

              if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.LEFT) and (Key.isDown(UP) and (Key.isDown(DOWN) and (Key.isDown(87) and (Key.isDown(65) and (Key.isDown(83) and (Key.isDown(68))))))))) {

              var ct:ColorTransform=player.transform.colorTransform;

              ct.rgb=0xff00ff;

              player.transform.colorTransform=ct;

              }

              1 person found this helpful
              • 4. Re: Change color
                xCyper Level 1

                i've added you code but now i'm getting the error:

                The class or interface 'ColorTransform' could not be loaded.

                 

                and the character is glitching and not showing the movement cycle.

                 

                Any solutions?

                i'm sorry that my code is a mess, it's my first game i've made, in the future i will make my code better.

                • 5. Re: Change color
                  kglad Adobe Community Professional & MVP

                  did you import the ColorTransform class?

                  1 person found this helpful
                  • 6. Re: Change color
                    xCyper Level 1

                    thank you for your help so far but I'm sorry, i don't think i have,

                    how do i do this?

                    i'd really appreciate the help so far.

                    • 7. Re: Change color
                      kglad Adobe Community Professional & MVP

                      you need this attached to your main timeline,

                       

                      import flash.geom.ColorTransform;

                      1 person found this helpful
                      • 8. Re: Change color
                        xCyper Level 1

                        It still doesn't work,

                        Is to possible to send my game so you can look at it and see what's wrong?

                         

                        thank you for your help

                        • 9. Re: Change color
                          kglad Adobe Community Professional & MVP

                          i don't download and correct files unless i'm hired.  free help i offer via the adobe forums.

                           

                          you most likely have a reference error. eg, is player the correct reference to the object you want to re-color?

                          • 10. Re: Change color
                            xCyper Level 1

                            yes, player is the correct reference.

                            i've put

                            onClipEvent (load) {

                              import flash.geom.ColorTransform;

                            }

                            in front of the code.

                            my theory is (and this may sound stupid)

                            that i need a symbol or something called ColorTransform. Is that true or am i thinking to much?

                            it's not giving me an error but also not chaning the color

                            • 11. Re: Change color
                              kglad Adobe Community Professional & MVP

                              yes, you need a variable that's a colortransform.  that is created in this line:

                               

                              var ct:ColorTransform=player.transform.colorTransform;

                               

                              (where ct is defined as a colortransform).

                               

                              use the trace statement to debug.

                               

                              what's the following show:

                               

                              onClipEvent (enterFrame) { powerleft = 5; powerright = 10; powerupdown = 7;

                              if(Key.isDown(Key.SHIFT)){

                              powerright = 15;

                              }

                              else {

                              powerright = 10;

                              }

                              if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.LEFT) and (Key.isDown(UP) and (Key.isDown(DOWN) and (Key.isDown(87) and (Key.isDown(65) and (Key.isDown(83) and (Key.isDown(68))))))))) {

                              var ct:ColorTransform=player.transform.colorTransform;

                              ct.rgb=0xff00ff;

                              player.transform.colorTransform=ct;

                              trace('color change: '+player)

                              }

                              .

                              .

                               

                              1 person found this helpful
                              • 12. Re: Change color
                                xCyper Level 1

                                it still doesn't work.

                                do i need to add something in my library?

                                my code in player is:

                                 

                                onClipEvent (load) {

                                  import flash.geom.ColorTransform;

                                }

                                onClipEvent (enterFrame) { powerleft = 5; powerright = 10; powerupdown = 7;

                                if(Key.isDown(Key.SHIFT)){

                                powerright = 15;

                                }

                                else {

                                powerright = 10;

                                }

                                if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.LEFT) and (Key.isDown(UP) and (Key.isDown(DOWN))))) {

                                var ct:ColorTransform=player.transform.ColorTransform;

                                ct.rgb=0xff00ff;

                                player.transform.ColorTransform=ct;

                                trace('color change: '+player)

                                }

                                if (Key.isDown(Key.RIGHT)) { this._xscale = 100; this._x += powerright; if(jumping){ this.gotoAndStop(3);

                                }

                                else { this.gotoAndStop(1); }

                                }

                                if (Key.isDown(Key.LEFT)) { this._xscale = 100; this._x -= powerleft; if(jumping){ this.gotoAndStop(3);

                                }

                                else { this.gotoAndStop(1); }

                                }

                                if (Key.isDown(Key.UP)) { this._xscale = 100; this._y -= powerupdown; if(jumping){ this.gotoAndStop(3);

                                }

                                else { this.gotoAndStop(1); }

                                }

                                if (Key.isDown(Key.DOWN)) { this._xscale = 100; this._y += powerupdown; if(jumping){ this.gotoAndStop(3);

                                }

                                else { this.gotoAndStop(1); }

                                }

                                if (!Key.isDown(Key.DOWN) and (!Key.isDown(Key.UP) and (!Key.isDown(Key.LEFT) and (!Key.isDown(Key.RIGHT))))) { this.gotoAndStop(2); }

                                }

                                onClipEvent(enterFrame) { if(_root.player.hitTest(_root.wall1)) { this._x +=25; }

                                }

                                onClipEvent(enterFrame) { if(_root.player.hitTest(_root.wall2)) { this._x -=25; }

                                }

                                onClipEvent(enterFrame) { if(_root.player.hitTest(_root.ceiling)) { this._y +=25; }

                                }

                                onClipEvent(enterFrame) { if(_root.player.hitTest(_root.ground)) { this._y -=25; }

                                }

                                 

                                Is there anything i'm missing, is there something wrong with the code or something else?

                                it's not giving any errors but just not changing the color

                                • 13. Re: Change color
                                  kglad Adobe Community Professional & MVP

                                  what trace output do you see when pressing the keys that should change the color?

                                  • 14. Re: Change color
                                    xCyper Level 1

                                    If with trace output you mean text in the output screen (between timeline and compiler errors)

                                    its blanc, also when i press the keys

                                    • 15. Re: Change color
                                      xCyper Level 1

                                      I've found the solution.

                                      I've made it so that when you press (in this case) CONTROL the character will go from character on frame 1 to character on frame 3, the character on frame 3 is a different color.

                                       

                                      My new code is:

                                       

                                      onClipEvent (enterFrame) { powerleft = 5; powerright = 10; powerupdown = 7; One = 1;

                                      if(Key.isDown(Key.SHIFT)){

                                      powerright = 15;

                                      }

                                      else {

                                      powerright = 10;

                                      }

                                      if (Key.isDown(Key.CONTROL)) {

                                      One = 3;

                                      }

                                      if (Key.isDown(Key.RIGHT)) { this._xscale = 100; this._x += powerright; if(jumping){ this.gotoAndStop(3);

                                      }

                                      else { this.gotoAndStop(One); }

                                      }

                                      if (Key.isDown(Key.LEFT)) { this._xscale = 100; this._x -= powerleft; if(jumping){ this.gotoAndStop(3);

                                      }

                                      else { this.gotoAndStop(One); }

                                      }

                                      if (Key.isDown(Key.UP)) { this._xscale = 100; this._y -= powerupdown; if(jumping){ this.gotoAndStop(3);

                                      }

                                      else { this.gotoAndStop(One); }

                                      }

                                      if (Key.isDown(Key.DOWN)) { this._xscale = 100; this._y += powerupdown; if(jumping){ this.gotoAndStop(3);

                                      }

                                      else { this.gotoAndStop(One); }

                                      }

                                      if (!Key.isDown(Key.DOWN) and (!Key.isDown(Key.UP) and (!Key.isDown(Key.LEFT) and (!Key.isDown(Key.RIGHT))))) { this.gotoAndStop(2); }

                                      }

                                      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.wall1)) { this._x +=25; }

                                      }

                                      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.wall2)) { this._x -=25; }

                                      }

                                      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.ceiling)) { this._y +=25; }

                                      }

                                      onClipEvent(enterFrame) { if(_root.player.hitTest(_root.ground)) { this._y -=25; }

                                      }

                                       

                                       

                                      Thank you for your help, unless you found another solution I'll close this thread in 24 hours

                                      • 16. Re: Change color
                                        kglad Adobe Community Professional & MVP

                                        you're welcome.

                                         

                                        (p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

                                        • 17. Re: Change color
                                          xCyper Level 1

                                          ok, i will