Skip to main content
xCyper
Known Participant
December 6, 2016
Question

Change color

  • December 6, 2016
  • 1 reply
  • 1683 views

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.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 6, 2016

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;

}

xCyper
xCyperAuthor
Known Participant
December 6, 2016

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.

kglad
Community Expert
Community Expert
December 6, 2016

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;

}