Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Using Variables to Specify Hex Color Values


MrStuntman
8/9/2006 9:38:11 PM
Hi, I've been working away on my webpage for a few days now and have run into a
bit of trouble.

In the backdrop of the flash scene, I have a bunch of actionscript controled
shapes that float from the bottom of the window to the top, reset, and repeat.
Within each shape, I have a layer that defines the color, and one that
determines the shade of said color. This is acheived through a simple solid
black movie clip placed over another 'color' movieclip. The solid black clip
has actionscript applied to it that determines it's alpha value, thereby
changing the shade of the overall color. As for the color movieclip, I have it
set up so that when I want to change the color of said clip, I just have to
open up my ftp and edit a text file containing a hex value that then effects
the color clip.

But anyway, heres my problem: for some reason when I get the hex value from
the external text file and try to apply it as the hex parameter for the
..setRGB, it doesn't work. No value seems to be obtained, and I don't know if
thats because of a faulty bit of coding, messed up variables, or if it can even
work like that.

I'm using Flash 6, and below is a link to a .fla file with all the actuall
coding and stuff already inplace. I would appreciate any help you can offer. ^.^

http://www.hackhalo.org/uploads/stuntypwnsyou/helpwouldbenice.fla

Though my explanation may have been a little hard to understand, I hope that
the .swf will be easier to go through and figure out. If theres anything else
you need from me to properly assess the problem I'm having, just ask.

Thank you.
kglad
8/9/2006 11:39:16 PM
MrStuntman
8/10/2006 1:27:08 AM
Well, the code for assigning the color is assigned to the "control clip" that I
have on the side of the document.

The code is:

onClipEvent (load) {
var colorfulcirc = new Color("_root.circle.circle");
colorfulcirc.setRGB(0xFFFFFF);
var colorfulcirc = new Color("_root.circle2.circle");
colorfulcirc.setRGB(0xFFFFFF);
var colorfulcirc = new Color("_root.circle3.circle");
colorfulcirc.setRGB(0xFFFFFF);
var colorfulcirc = new Color("_root.circle4.circle");
colorfulcirc.setRGB(0xFFFFFF);
// break from circles
var colorfulsqr = new Color("_root.square.square");
colorfulsqr.setRGB(0xFFFFFF);
var colorfulsqr = new Color("_root.square2.square");
colorfulsqr.setRGB(0xFFFFFF);
var colorfulsqr = new Color("_root.square3.square");
colorfulsqr.setRGB(0xFFFFFF);
var colorfulsqr = new Color("_root.square4.square");
colorfulsqr.setRGB(0xFFFFFF);
// break from squares
var colorfultri = new Color("_root.triangle.triangle");
colorfultri.setRGB(0xFFFFFF);
var colorfultri = new Color("_root.triangle2.triangle");
colorfultri.setRGB(0xFFFFFF);
var colorfultri = new Color("_root.triangle3.triangle");
colorfultri.setRGB(0xFFFFFF);
var colorfultri = new Color("_root.triangle4.triangle");
colorfultri.setRGB(0xFFFFFF);
}

Now, each of those 0xFFFFFF's should be assigned the correct variable that I
have downloaded from the external textfile. (Which would be, [b]circlecolor[/b]
for the cirlces, [b]squarecolor[/b] for the squares and [b]trianglecolor[/b]
for the triangles.

As for your second question, I have the "get variables" code stationed before
the actual use of the variables, so I figure it should work.
kglad
8/10/2006 2:16:35 AM
0xFFFFFF is a number, not a variable. and you can't assign a variable's value
to 0xFFFFFF.

in addition, flash will continue to execute code whether loading is complete
or not and almost certainly all code in the same movieclip frame with your
loadVariables statement will execute before loading is complete.

to remedy you would do something like the following:



lv=new LoadVars();
lv.onLoad=function(){
colorfulcirc.setRGB(lv.circlecolor); // assuming you have something like
&circlecolor=0xFF0000& in colorvars.txt and colorfulcirc has been instantiated.
}
lv.load("http://www.hackhalo.org/uploads/stuntypwnsyou/colorvars.txt");
MrStuntman
8/11/2006 2:36:42 PM
!

kglad
8/11/2006 3:20:29 PM
AddThis Social Bookmark Button