• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Change color

New Here ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

did you import the ColorTransform class?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

you need this attached to your main timeline,

import flash.geom.ColorTransform;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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)

}

.

.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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

its blanc, also when i press the keys

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

you're welcome.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

LATEST

ok, i will

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines