Copy link to clipboard
Copied
HELP!!
I'm trying to get a simple Tennis Court colorizer to work. I have 2 rows of buttons targeted to separate instances (inside court and outside court).
The rows of buttons color the instances the way they should, but not at the same time -- meaning; the top row colors the inside of the court, but when I click on any button in the bottom row, the outside of the court changes color correctly, but the inside of the court turns black.
Same thing happens in reverse. I need to be able to change colors on the inside and outside
I am a complete novice with Flash, but my client wanted this thing, and I'm trying to make it work. I've reverse engineered this from a nmber of sources, and trial and error. For the record, I have many (many) years of experience with Illustrator and Photoshop. Just don't use Flash, because I create usually static artwork for print.
I also need to have the color name appear above the button rows when a color is clicked.
Haven't gotten to that part yet.
Here's the page with the embedded .swf file:
http://www.jerryrussell.com/sandbox/TennisCourtColorizerCS6.html
Here's the Action Script:
// BUTTON ARRAYS with the instances of the buttons
var obtts:Array = [O_green1, O_green2, O_green3, O_blue1, O_blue2, O_tan, O_red];
var ibtts:Array = [I_green1, I_green2, I_green3, I_blue1, I_blue2, I_tan, I_red];
// sets an object with colors for each button
var set_outercolors:Object = {'O_green1':0x26822E, 'O_green2':0x1E592B, 'O_green3':0x104322, 'O_blue1':0x0665A4, 'O_blue2':0x023F5F, 'O_tan':0x766B4E, 'O_red':0x703730};
var set_innercolors:Object = {'I_green1':0x26822E, 'I_green2':0x1E592B, 'I_green3':0x104322, 'I_blue1':0x0665A4, 'I_blue2':0x023F5F, 'I_tan':0x766B4E, 'I_red':0x703730};
// sets a ColorTransform object
var oobj_color:ColorTransform = new ColorTransform();
var iobj_color:ColorTransform = new ColorTransform();
// traverse the "obtts" array with button instances
for(var o:int=0; o<obtts.length; o++) {
// set the color to each button
oobj_color.color = set_outercolors[obtts
obtts
// register CLICK event for each button
obtts
ibtts.addEventListener(MouseEvent.CLICK, changeColor);
}
// traverse the "ibtts" array with button instances
for(var i:int=0; i<ibtts.length; i++) {
// set the color to each button
iobj_color.color = set_innercolors[ibtts.name];
ibtts.transform.colorTransform = iobj_color;
// register CLICK event for each button
ibtts.addEventListener(MouseEvent.CLICK, changeColor);
}
// function called by CLICK events
function changeColor(evt:Event):void
{
// get the instance name of the clicked button
var b_name = evt.target.name;
// set and change the instance color
oobj_color.color = set_outercolors[b_name];
outer.transform.colorTransform = oobj_color;
iobj_color.color = set_innercolors[b_name];
inner.transform.colorTransform = iobj_color;
}
Copy link to clipboard
Copied
use the trace function to see what color your applying to your object's colorTransform.
Copy link to clipboard
Copied
the problem lies here:
/ set and change the instance color
oobj_color.color = set_outercolors[b_name];
outer.transform.colorTransform = oobj_color;
iobj_color.color = set_innercolors[b_name];
inner.transform.colorTransform = iobj_color;
you are setting both (inner/outer) colors everytime you click.
but if bname is an outer-color button he won`t find a corresponding inner-color and vice versa
thus it "resets" to 0x000000 (black);
you have to include a switch like this:
//look if the first string of the buttons name is an I or an O
switch(bname.substr(0,1){
case "O":
oobj_color.color = set_outercolors[b_name];
outer.transform.colorTransform = oobj_color;
break;
case "I":
iobj_color.color = set_innercolors[b_name];
inner.transform.colorTransform = iobj_color;
break;
}
Copy link to clipboard
Copied
Thank you!!
That worked, with one minor change:
This line:
switch(bname.substr(0,1){
was missing an underscore in b_name and a close paren after the subset.
switch(b_name.substr(0,1)){
Now it works like a charm.
Copy link to clipboard
Copied
Its totally these forums`fault to have no working syntax ckecker 😉
Copy link to clipboard
Copied
Yeah, syntax checker ... that's it for sure!
Thanks again. I've been wrestling with this for 2 days. I know nothing about Flash, but I do have some skils for code detective work and reverse engineering. Just enough to get me into trouble.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now