.setRGB

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

yourClip._alpha = number from 0 to 100

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

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

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

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

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.

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

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

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.

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?

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]

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]

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

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

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

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

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

the opacity change:)

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.

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

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

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

Optimization… Yes… :smiley:

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

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 :frowning: