# .setRGB

**URL:** <https://forum.kirupa.com/t/setrgb/15448>\
**Category:** flash\
**Created:** [March 14, 2003, 7:03am UTC](https://forum.kirupa.com/t/setrgb/15448 "2003-03-14T07:03:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobody](https://avatars.discourse-cdn.com/v4/letter/n/94ad74/32.png) [@nobody](https://forum.kirupa.com/u/nobody)\
**Post date:** [March 14, 2003, 7:03am UTC](https://forum.kirupa.com/t/setrgb/15448/1 "2003-03-14T07:03:49Z")

</div>

I was wondering if there is a way to set the opacity of an object similar to the .setRGB thing… I’m sure this is a dumb question but I’m just curious

-thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:05am UTC](https://forum.kirupa.com/t/setrgb/15448/2 "2003-03-14T07:05:32Z")

</div>

yourClip.\_alpha = number from 0 to 100

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:08am UTC](https://forum.kirupa.com/t/setrgb/15448/3 "2003-03-14T07:08:47Z")

</div>

it doesn’t work  
or im stupid  
or it doesn’t work

```php
on (keyPress "1") {
	var colorful = new Color("_root.shapes");
	colorful._alpha(50);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:10am UTC](https://forum.kirupa.com/t/setrgb/15448/4 "2003-03-14T07:10:43Z")

</div>

i changed it to this… cuz i thought it might be smarter…er… but it still doesnt work

```php
on (keyPress "1") {
	var opacity = new _alpha("_root.shapes");
	opacity._alpha(50);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:11am UTC](https://forum.kirupa.com/t/setrgb/15448/5 "2003-03-14T07:11:02Z")

</div>

because the alpha isn’t a color, its a property.

And they way you are using it, you are saying alpha is part of your color object.

You have to target the clip in which you want the alpha to change.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:11am UTC](https://forum.kirupa.com/t/setrgb/15448/6 "2003-03-14T07:11:43Z")

</div>

yeah, i realized that for the first one, can you tell me what is wrong with the second one?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:13am UTC](https://forum.kirupa.com/t/setrgb/15448/7 "2003-03-14T07:13:15Z")

</div>

> \*Originally posted by xxviii \*  
> \*\*i changed it to this… cuz i thought it might be smarter…er… but it still doesnt work

```php
on (keyPress "1") {
	var opacity = new _alpha("_root.shapes");
	opacity._alpha(50);
}

```

\*\*

Ahhhh, thats even worse.

new \_alpha doesn’t exist.

keyPress “1” doesn’t exist either.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:14am UTC](https://forum.kirupa.com/t/setrgb/15448/8 "2003-03-14T07:14:07Z")

</div>

wooohoooo

the good news is im just trying to expiriment with stuff… so it’s not too horrible it doesnt work… any magical words of wisdom of how to do it or should i just scrap it?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:22am UTC](https://forum.kirupa.com/t/setrgb/15448/9 "2003-03-14T07:22:31Z")

</div>

Throw these on a FRAMES actions…  
[AS]opacityListener = new Object();  
opacityListener.onKeyDown = function() {  
if (Key.isDown(49)) {  
myClip.\_alpha = 50;  
}  
};  
Key.addListener(opacityListener);[/AS]  
opacityListener = new Object();

Creates a new object that we will use to detect key presses.

opacityListener.onKeyDown

create dynamic event handler checking if a key is pressed

if (Key.isDown(49))

check if keyCode 49 is pressed (“1” key)

myClip.\_alpha = 50

If that is true, then it sets the clip with the instance name “myClip” to \_alpha = 50.

Key.addListener(opacityListener)

Adds the listener that listens for a key to be pressed.

How did I get the key code? I wrote this simple script long ago to make it easier for me to figure out what the keycode for certain keys are.

Just create a new document, throw this in the frame 1s actions then test the movie. Press keys on your keyboard and it will show the keycode result in the output window.

[AS]keyListener = new Object();  
keyListener.onKeyDown = function() {  
keypressed = Key.getCode();  
trace(keypressed);  
};  
Key.addListener(keyListener);[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:24am UTC](https://forum.kirupa.com/t/setrgb/15448/10 "2003-03-14T07:24:43Z")

</div>

Or you can just apply this directly to the movie clip… not very efficient to run an enterFrame just to check if a key is pressed if you ask me though. Perhaps I could be wrong.

[AS]onClipEvent(enterFrame){  
if (Key.isDown(49)) {  
this.\_alpha = 50;  
}  
}[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:26am UTC](https://forum.kirupa.com/t/setrgb/15448/11 "2003-03-14T07:26:56Z")

</div>

I think I did something wrong… I’ll explain what I did, and you tell me all the ways im dumb  
I have an on keypress for every letter in the alphabet and it makes it change to a different color, this works all fine and dandy… then at the bottom of this i threw on what you said… and when i ran the movie, it just showed it in the output window…

i appreciate all the help tho

if your tired of my annoyingness just tell me

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:29am UTC](https://forum.kirupa.com/t/setrgb/15448/12 "2003-03-14T07:29:06Z")

</div>

I didn’t have it on the frame like u said in big letters… oops… but it still isnt doing anything…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:29am UTC](https://forum.kirupa.com/t/setrgb/15448/13 "2003-03-14T07:29:08Z")

</div>

It would be easier to troubleshoot if you could supply your source file 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:31am UTC](https://forum.kirupa.com/t/setrgb/15448/14 "2003-03-14T07:31:13Z")

</div>

alright… sorry, i shoulda done that in the first place  
anywho… here it is

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:34am UTC](https://forum.kirupa.com/t/setrgb/15448/15 "2003-03-14T07:34:36Z")

</div>

Um… I get to see the color changes depending on the keycode… What is not working??? 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:35am UTC](https://forum.kirupa.com/t/setrgb/15448/16 "2003-03-14T07:35:05Z")

</div>

the opacity change:)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:36am UTC](https://forum.kirupa.com/t/setrgb/15448/17 "2003-03-14T07:36:27Z")

</div>

Well whaddaya know keyPress “1” actually IS something. OOPS.

Anywho. You forgot to change myClip.\_alpha to shapes.\_alpha.

And wow, your code needs some optimization. I will see what I can cook up.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:37am UTC](https://forum.kirupa.com/t/setrgb/15448/18 "2003-03-14T07:37:52Z")

</div>

haha… i just realized that… i am so dumb

and im sure my code does need optimization, but im just expirimenting… just tryin to learn myself some stuffs…

but thanks a lot for your help

i cant believe i didnt change the name… ha

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:38am UTC](https://forum.kirupa.com/t/setrgb/15448/19 "2003-03-14T07:38:30Z")

</div>

Yup… As lostinbeta already told you, you forgot to change the name of the movieclip that you want to change the \_alpha property…

```auto
opacityListener = new Object();
opacityListener.onKeyDown = function()
{
	if (Key.isDown(49))
	{
		_root.shapes._alpha = 50;
	}
};
Key.addListener(opacityListener);

```

Optimization… Yes… 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 14, 2003, 7:41am UTC](https://forum.kirupa.com/t/setrgb/15448/20 "2003-03-14T07:41:59Z")

</div>

Well I WAS working on optimizing until Flash decided to crash on me due to lack of memory resources ☹

I got this far…

No actions on the frame…

And movie clips actions are as follows…

[AS]onClipEvent (load) {  
var colorful = new Color(this);  
}  
on (keyPress “1”) {  
this.\_alpha = 50;  
}  
on (keyPress “a”) {  
colorful.setRGB(0x333333);  
}  
on (keyPress “b”) {  
colorful.setRGB(0x333366);  
}  
on (keyPress “c”) {  
colorful.setRGB(0x333399);  
}  
on (keyPress “d”) {  
colorful.setRGB(0x336633);  
}  
on (keyPress “e”) {  
colorful.setRGB(0x336666);  
}  
on (keyPress “f”) {  
colorful.setRGB(0x336699);  
}  
on (keyPress “g”) {  
colorful.setRGB(0x339933);  
}  
on (keyPress “h”) {  
colorful.setRGB(0x339966);  
}  
on (keyPress “i”) {  
colorful.setRGB(0x339999);  
}  
on (keyPress “j”) {  
colorful.setRGB(0x663333);  
}  
on (keyPress “k”) {  
colorful.setRGB(0x663366);  
}  
on (keyPress “l”) {  
colorful.setRGB(0x663399);  
}  
on (keyPress “m”) {  
colorful.setRGB(0x666633);  
}  
on (keyPress “n”) {  
colorful.setRGB(0x666666);  
}  
on (keyPress “o”) {  
colorful.setRGB(0x666699);  
}  
on (keyPress “p”) {  
colorful.setRGB(0x669933);  
}  
on (keyPress “q”) {  
colorful.setRGB(0x669966);  
}  
on (keyPress “r”) {  
colorful.setRGB(0x669999);  
}  
on (keyPress “s”) {  
colorful.setRGB(0x993333);  
}  
on (keyPress “t”) {  
colorful.setRGB(0x993366);  
}  
on (keyPress “u”) {  
colorful.setRGB(0x993399);  
}  
on (keyPress “v”) {  
colorful.setRGB(0x996633);  
}  
on (keyPress “w”) {  
colorful.setRGB(0x996699);  
}  
on (keyPress “x”) {  
colorful.setRGB(0x999933);  
}  
on (keyPress “y”) {  
colorful.setRGB(0x999966);  
}  
on (keyPress “z”) {  
colorful.setRGB(0x999999);  
}[/AS]

If anyone else wishes to continue optimizing, be my guest, I can’t open Flash right now ☹

[Next page](https://forum.kirupa.com/t/setrgb/15448.md?page=2)
