Forum Topic: As:actionscripted Color

(3,111 views • 18 replies)

This topic is 1 page long.

<< < > >>
None

Thomas

Reply To Post Reply & Quote

Posted at: 12/13/05 09:07 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833

AS:Main
_________________________________________
Hi!This tutorial is going to explain how to change an objects color through ActionScript,such as in Rainbow Ball by Glaiel_Gamer and GAMECUBICLE.

Now there are two different ways to do this.First of all,there is just strait frame color changing,as in if your object is on a certain frame,you use the ActionScript to change the color.The instance name I'm going to use is Item.

Part 1 Test

First of all,here is the code you put on the frame to change an objects color(on specific frame)

var item = new Color("item");
item.setRGB(0x0000FF);

Simple?Well I'll explain a bit.

First,you will be setting the variable with 'var'.My variable name is item.'new Color' will...erm...define what the variable is used for(?) and "item"(in paranthesis(whatever)) is the instance name of the object being changed.

'item.setRGB(color);' is the new color of the item.Where '0x0000FF' is at is where your color goes.Make sure there is always '0x' at the beginning.Below are a couple color codes...

FF0000 = Red
0000FF = Blue
00FF00 = Green
FFFF00 = Yellow

Those are just basic codes for colors.If you want to get the color,then just go to your color menu,roll over a color,and where it says '#(numbers)' is the code.Moving on...

Part 2 Test

Now,instead of changing an object on a frame,we will use a code to change a color on a Key press.

This code goes in the first frame,along with a MovieClip instanced 'item'...

item.onEnterFrame = function() {
var item = new Color("item");
if (Key.isDown(Key.SPACE)) {
item.setRGB(0x0000FF);
} else {
item.setRGB(0xFF0000);
}
};

Now,this is pretty much the same thing,but with an 'if' and 'onEnterFrame'.Explanation...

'item.onEnterFrame=function(){}' is for setting the frame function....or something.It's basically like a ClipEvent,but for the frame.Always before the 'onEnterFrame' you put the instance of the item you're changing.I've already explained what 'var item= new Color("item") does.I'm sure everyone knows what an 'if' statement is...and if not...Click Here.I've also already explained the RGB part,it's just redone with an 'if' and an 'else'(to set the RGB back).Moving on to the final color part...

Part 3 Test

Now,in this part,you can use the arrow keys to move around,and when you hit an object,you change colors!Yay!

Here are some things you'll need in this part...

Character Instance of "item"
Create a Movieclip,Instance of "red" and color of red
Create a Movieclip,Instance of "yellow" and color of yellow
Create a Movieclip,Instance of "blue" and color of blue
Create a Movieclip,Instance of "green" and color of green

I find it a lot easier and space saving to just copy the character,make it smaller,and change it's color with the 'color' thingy that's built in.

So,here is the code of your character...

onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed;
}
if (Key.isDown(Key.DOWN)) {
this._y += speed;
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
}
if (this.hitTest(_root.red)) {
var item = new Color(this);
item.setRGB(0xFF0000);
} else if (this.hitTest(_root.blue)) {
var item = new Color(this);
item.setRGB(0x0000FF);
} else if (this.hitTest(_root.green)) {
var item = new Color(this);
item.setRGB(0x00FF00);
} else if (this.hitTest(_root.yellow)) {
var item = new Color(this);
item.setRGB(0xFFFF00);
}
}

Basic Movement
Loops and Conditions
Clip Events

I'm sure those links will cover explaining the code,plus the stuff I've already posted.

Well,that's all I've got on color...hope it helps.

I wonder why it's so long,only being about color?

None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/13/05 09:19 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

i prefer setTransform

onClipEvent(load){
rgb = new Color(this);
resetTransform = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
hitTransform = {ra:100, rb:255, ga:100, gb:50, ba:0, bb:00, aa:100, ab:0};
i=0
}
onClipEvent(mouseDown){
rgb.setTransform(i%2?hitTransform:resetTra
nsform);
i++
}

Some times my "L" key decides not to work.


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/13/05 09:20 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

sorry my post might have seemed kind of pompus, your tutorial was accually really informitive.

Some times my "L" key decides not to work.


None

Thomas

Reply To Post Reply & Quote

Posted at: 12/13/05 09:27 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833

Your code confuses me,and is a bit longer...I think...compared to a the codes I used...cept for the character one.


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/13/05 09:55 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

well the thing is, your code changes it to a solid color. transform takes each individual color and changes them each differently.
example

Some times my "L" key decides not to work.


None

Thomas

Reply To Post Reply & Quote

Posted at: 12/13/05 09:58 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833

I see...hmm.

Well,I guess my codes are basic...and anyway,with the third part,you can add something to the front of that MC and it will use the Soften Fill Edge and all that...erm.

Ok.


None

fwe

Reply To Post Reply & Quote

Posted at: 12/13/05 10:00 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

At 12/13/05 09:58 PM, -Thomas- wrote: I see...hmm.

Well,I guess my codes are basic...and anyway,with the third part,you can add something to the front of that MC and it will use the Soften Fill Edge and all that...erm.

Ok.

but importentboys method is more efficient

wtfbbqhax


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/13/05 10:10 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

At 12/13/05 10:00 PM, fwe wrote:
At 12/13/05 09:58 PM, -Thomas- wrote: I see...hmm.

Well,I guess my codes are basic...and anyway,with the third part,you can add something to the front of that MC and it will use the Soften Fill Edge and all that...erm.

Ok.
but importentboys method is more efficient

IMPOTENT

it is but that extra effects isn't need that much, so for simplicity's sake it's good to use tom's. except of course if you need to return a mc color back to its orignal(non unicolored) color scheme.

Some times my "L" key decides not to work.


None

Thomas

Reply To Post Reply & Quote

Posted at: 12/13/05 10:21 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/13/05 10:32 PM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

At 12/13/05 10:21 PM, -Thomas- wrote: What do you mean?

i mean that even though my way is more efficient, its not worth the time it takes to get it right (set transform takes alot of time messing around with numbers and theres alot of trial and error). and most of the time setRGB() will do just fine.

the only thing is. when you use setRGB (and set transform) and you want to get it back to normal (lets say the original object was red with a blue dot in the middle) it would be impossible to reset the colors using setRGB. you would have to use the following code

rgb = new Color(this);
resetTransform = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
rgb.setTransform(resetTransform)

Some times my "L" key decides not to work.


None

Thomas

Reply To Post Reply & Quote

Posted at: 12/13/05 10:36 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833


None

Rantzien

Reply To Post Reply & Quote

Posted at: 12/14/05 03:32 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426


None

Thomas

Reply To Post Reply & Quote

Posted at: 12/14/05 10:55 AM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833

At 12/14/05 03:32 AM, Santazien wrote: AS: Dynamic Color Changes

You didn't explain it :(


None

IWantSomeCookies

Reply To Post Reply & Quote

Posted at: 12/14/05 11:03 AM

IWantSomeCookies LIGHT LEVEL 13

Sign-Up: 08/20/04

Posts: 3,295

Real nice tutorial, and really well explained. I learnt alot from it, thanks.

"Actually, the server timed out trying to remove all your posts..."
-TomFulp


None

Rantzien

Reply To Post Reply & Quote

Posted at: 12/14/05 11:18 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

At 12/14/05 10:55 AM, -Snow- wrote:
At 12/14/05 03:32 AM, Santazien wrote: AS: Dynamic Color Changes
You didn't explain it :(

The part that changes the colour in this tutorial is wrongly explained. The rest is just unrelated stuff that doesn't really have to do with colour, stuff that is covered in other threads. So, if this is going in the list, I would either have deleted mine, or added this to the specific projects section. But I'm not Denvish.

BBS Signature

Happy

luigis-toilet

Reply To Post Reply & Quote

Posted at: 4/17/06 06:44 AM

luigis-toilet LIGHT LEVEL 08

Sign-Up: 01/03/06

Posts: 104

Nice tutorial.


Thinking

luigis-toilet

Reply To Post Reply & Quote

Posted at: 4/17/06 06:45 AM

luigis-toilet LIGHT LEVEL 08

Sign-Up: 01/03/06

Posts: 104

Many light guys here :P.


None

Sweettatas

Reply To Post Reply & Quote

Posted at: 4/20/07 10:11 PM

Sweettatas NEUTRAL LEVEL 01

Sign-Up: 04/20/07

Posts: 1

I really liked this tut. I learned a bit and it amused me for a few minutes! =D I just recently took an interest in Flash, I know HTML and CSS, but actionscript is different.... a wee bit.


None

jettisoner

Reply To Post Reply & Quote

Posted at: 12/15/07 02:25 PM

jettisoner LIGHT LEVEL 06

Sign-Up: 12/08/07

Posts: 5

hmmmm!!!
How can i make a ball's color changing randomly every frame


All times are Eastern Standard Time (GMT -5) | Current Time: 05:32 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!