PDA

View Full Version : .setRGB



nobody
March 14th, 2003, 02:03 AM
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

lostinbeta
March 14th, 2003, 02:05 AM
yourClip._alpha = number from 0 to 100

nobody
March 14th, 2003, 02:08 AM
it doesn't work
or im stupid
or it doesn't work

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

nobody
March 14th, 2003, 02:10 AM
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);
}

lostinbeta
March 14th, 2003, 02:11 AM
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.

nobody
March 14th, 2003, 02:11 AM
yeah, i realized that for the first one, can you tell me what is wrong with the second one?

lostinbeta
March 14th, 2003, 02:13 AM
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.

nobody
March 14th, 2003, 02:14 AM
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?

lostinbeta
March 14th, 2003, 02:22 AM
Throw these on a FRAMES actions..
opacityListener = new Object();
opacityListener.onKeyDown = function() {
if (Key.isDown(49)) {
myClip._alpha = 50;
}
};
Key.addListener(opacityListener);
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.

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

lostinbeta
March 14th, 2003, 02:24 AM
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.

onClipEvent(enterFrame){
if (Key.isDown(49)) {
this._alpha = 50;
}
}

nobody
March 14th, 2003, 02:26 AM
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

nobody
March 14th, 2003, 02:29 AM
I didn't have it on the frame like u said in big letters.. oops.. but it still isnt doing anything..

lostinbeta
March 14th, 2003, 02:29 AM
It would be easier to troubleshoot if you could supply your source file :)

nobody
March 14th, 2003, 02:31 AM
alright.. sorry, i shoulda done that in the first place
anywho.. here it is

CyanBlue
March 14th, 2003, 02:34 AM
Um... I get to see the color changes depending on the keycode... What is not working??? ;)

nobody
March 14th, 2003, 02:35 AM
the opacity change:)

lostinbeta
March 14th, 2003, 02:36 AM
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.

nobody
March 14th, 2003, 02:37 AM
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

CyanBlue
March 14th, 2003, 02:38 AM
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... :D

lostinbeta
March 14th, 2003, 02:41 AM
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...

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);
}



If anyone else wishes to continue optimizing, be my guest, I can't open Flash right now :(

nobody
March 14th, 2003, 02:44 AM
that's crazy.. i just spent so much time doin this


opacityListener = new Object();
opacityListener.onKeyDown = function() {
if (Key.isDown(49)) {
shapes._alpha = 10;
}
if (Key.isDown(50)) {
shapes._alpha = 20;
}
if (Key.isDown(51)) {
shapes._alpha = 30;
}
if (Key.isDown(52)) {
shapes._alpha = 40;
}
if (Key.isDown(53)) {
shapes._alpha = 50;
}
if (Key.isDown(54)) {
shapes._alpha = 60;
}
if (Key.isDown(55)) {
shapes._alpha = 70;
}
if (Key.isDown(56)) {
shapes._alpha = 80;
}
if (Key.isDown(57)) {
shapes._alpha = 90;
}
if (Key.isDown(58)) {
shapes._alpha = 100;
}
};
Key.addListener(opacityListener);


I was just followin the tutorial and what you did and stuff.. but dang.. lol.. i have a lot to learn

lostinbeta
March 14th, 2003, 02:46 AM
Well I could get all "obfuscated" and stuff, and in that case, my listener code would be better and probably less lines, but you would need the keyCode to each character unfortunately.

And you could do an if/else instead of if, if, if, if, etc.

nobody
March 14th, 2003, 02:48 AM
ohhh.. well i did save your little key code thingie..

thanks a lot for your help lost and cyan.. im goin to bed now tho.. im glad i got this far

thanks a ton for your help again

I'll screw with it some more tomorrow.. this is fun.. night guys

PS: obfuscated?

lostinbeta
March 14th, 2003, 02:52 AM
Obfuscating code is condensing it down. To truly obfuscate though, the code would be unreadable really.

Mine wouldn't be that obfuscated, just minor stuff.

CyanBlue
March 14th, 2003, 03:00 AM
Some thing like this???
colorArray = new Array("0x333333", "0x333366", "0x333399", "0x336633",
"0x336666", "0x336699", "0x339933", "0x339966",
"0x339999", "0x663333", "0x663366", "0x663399",
"0x666633", "0x666666", "0x666699", "0x669933",
"0x669966", "0x669999", "0x993333", "0x993366",
"0x993399", "0x996633", "0x996699", "0x999933",
"0x999966", "0x999999");
opacityListener = new Object();
opacityListener.onKeyDown = function()
{
if ((Key.getCode() >= 48) && (Key.getCode() <= 57))
{
if (Key.getCode() == 48)
shapes._alpha = 100;
else
shapes._alpha = (Key.getCode() - 48) * 10;
}
else if ((Key.getCode() >= 65) && (Key.getCode() <= 90))
{
var colorful = new Color("_root.shapes");
colorful.setRGB(colorArray[Key.getCode() - 65]);
}
};
Key.addListener(opacityListener);

lostinbeta
March 14th, 2003, 03:06 AM
babling. I can't test it, but it looks like what I had in my mind to try out :)

CyanBlue
March 14th, 2003, 03:10 AM
I know that you cannot check the code out, that's why I just created bogus code so that xxviii can check it out and get into the swampt... :P Kidding... ;)

You still having that RAM problem, lostinbeta??? :hair:

lostinbeta
March 14th, 2003, 03:12 AM
Yep yep, still having that problem :( My comp is getting better though, I can actually open Flash now!!!! YAY!!!! (well at least for a little bit).... and and... the other day I could actually open Photoshop and create a new footer/avatar!!!!!

Granted it ran like crap, but before I would get a memory usage error. So somehow it improved since then :P =)

CyanBlue
March 14th, 2003, 03:23 AM
Hehe... I hope you can figure out how to fix it soon... (I thought that somebody offered you one if I remember correctly...)
Well... I got bigger problem... My old PII 300 on 56k is lagging like hell when I am in Kirupa due to lots of SWF footers... It's gotta a little bit better after you guys forced the size restriction and such, but it is bad... Oh, well... What can I do about it??? :(

lostinbeta
March 14th, 2003, 03:25 AM
Wow, now that is a bad case senario :(

You could disable the viewing of footers for you. That should help.


Just go to UserCP/Edit Options/

In there will be something that says...


Show user's signatures in their posts? Yes No

CyanBlue
March 14th, 2003, 03:30 AM
Yes, I know... I don't really want to disable it because there are some good ones that my eyes like... ;) Besides, I did turn that off when I first came here but I didn't see much difference...

lostinbeta
March 14th, 2003, 03:32 AM
Hrmm, everyone I know that turns them off says the forum runs so much faster.


Alright, I am so off to bed now. I am tired(-:

Goodnight :sleep:

CyanBlue
March 14th, 2003, 03:35 AM
Yup... Good night... I'll be off soon too... ;)

nobody
March 14th, 2003, 09:49 AM
cyanblue.. i tried that code you said but it didnt seem to work, i was probably doing it wrong tho. im not good with all that loopy stuff.. but that probably wasnt even a loop.. cuz thats how dumb i am

thanks for the help tho

CyanBlue
March 14th, 2003, 10:16 AM
Here you go... ;)

nobody
March 14th, 2003, 10:36 AM
wow, thats pretty cool

thanks man..

once i can understan how u did that ill be a lot happier

thank you:)

senocular
March 14th, 2003, 10:50 AM
I dont think I saw this mentioned, but you can set alpha with the color object. Consider this function which will let you set RGB and alpha at once



Color.prototype.setRGBA = function(hex, a){
this.setRGB(hex);
this.setTransform({aa:a})
}



new Color(shapes).setRGBA(0x336699, 50);


Also, depending on those colors, you might be able to reduce the typing of all those hexes by making them a function of the keycode etc

yada yada yada ;)

nobody
March 14th, 2003, 10:59 AM
lol im so lost
i really suck at actionscript.. im still just learning it.. but thank you..

i think i almost understand what your sayin but i have no idea how i would actually apply it to something.. but oh well

thanks

lostinbeta
March 14th, 2003, 12:06 PM
Originally posted by senocular
I dont think I saw this mentioned, but you can set alpha with the color object. Consider this function which will let you set RGB and alpha at once



Color.prototype.setRGBA = function(hex, a){
this.setRGB(hex);
this.setTransform({aa:a})
}



new Color(shapes).setRGBA(0x336699, 50);


Also, depending on those colors, you might be able to reduce the typing of all those hexes by making them a function of the keycode etc

yada yada yada ;)

I did not know that. Interesting. Thanks :)

CyanBlue
March 15th, 2003, 04:02 AM
Yup... That's a neat one... Thanks senocular... =)