Be a Supporter!

As:actionscripted Color

  • 3,906 Views
  • 18 Replies
New Topic Respond to this Topic
Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
As:actionscripted Color Dec. 13th, 2005 @ 09:07 PM Reply

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?

wat
a compessor wil raise the volume while lowering the db - chronamut

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to As:actionscripted Color Dec. 13th, 2005 @ 09:19 PM Reply

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++
}

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to As:actionscripted Color Dec. 13th, 2005 @ 09:20 PM Reply

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

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As:actionscripted Color Dec. 13th, 2005 @ 09:27 PM Reply

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


wat
a compessor wil raise the volume while lowering the db - chronamut

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to As:actionscripted Color Dec. 13th, 2005 @ 09:55 PM Reply

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

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As:actionscripted Color Dec. 13th, 2005 @ 09:58 PM Reply

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.


wat
a compessor wil raise the volume while lowering the db - chronamut

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As:actionscripted Color Dec. 13th, 2005 @ 10:00 PM Reply

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

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to As:actionscripted Color Dec. 13th, 2005 @ 10:10 PM Reply

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.

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As:actionscripted Color Dec. 13th, 2005 @ 10:21 PM Reply

What do you mean?


wat
a compessor wil raise the volume while lowering the db - chronamut

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to As:actionscripted Color Dec. 13th, 2005 @ 10:32 PM Reply

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)

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As:actionscripted Color Dec. 13th, 2005 @ 10:36 PM Reply

else

:)


wat
a compessor wil raise the volume while lowering the db - chronamut

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to As:actionscripted Color Dec. 14th, 2005 @ 03:32 AM Reply

AS: Dynamic Color Changes


BBS Signature
Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As:actionscripted Color Dec. 14th, 2005 @ 10:55 AM Reply

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

You didn't explain it :(


wat
a compessor wil raise the volume while lowering the db - chronamut

IWantSomeCookies
IWantSomeCookies
  • Member since: Aug. 20, 2004
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to As:actionscripted Color Dec. 14th, 2005 @ 11:03 AM Reply

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

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to As:actionscripted Color Dec. 14th, 2005 @ 11:18 AM Reply

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
luigis-toilet
luigis-toilet
  • Member since: Jan. 3, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As:actionscripted Color Apr. 17th, 2006 @ 06:44 AM Reply

Nice tutorial.

luigis-toilet
luigis-toilet
  • Member since: Jan. 3, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As:actionscripted Color Apr. 17th, 2006 @ 06:45 AM Reply

Many light guys here :P.

Sweettatas
Sweettatas
  • Member since: Apr. 20, 2007
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to As:actionscripted Color Apr. 20th, 2007 @ 10:11 PM Reply

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.

jettisoner
jettisoner
  • Member since: Dec. 8, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to As:actionscripted Color Dec. 15th, 2007 @ 02:25 PM Reply

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