F5 Is there a way to shorten this code please?

This code for a painting game is getting a bit lengthy. Is there a way to abbreviate it? The targets “/w” etc are movie clips of paint colour, the labels are different states within the paintbrush movie clip (to show current paint colour), and the targets a1-b22 are areas of the pictures which change colour. Thanks.

on (press) {
startDrag ("_root.brush");
}
on (release) {
stopDrag ();
if (_root.brush._droptarget == “/w”) {
_root.brush.gotoandStop(“w”);
}
if (_root.brush._droptarget == “/bs”) {
_root.brush.gotoandStop(“bs”);
}
if (_root.brush._droptarget == “/g”) {
_root.brush.gotoandStop(“g”);
}
if (_root.brush._droptarget == “/gp”) {
_root.brush.gotoandStop(“gp”);
}
if (_root.brush._droptarget == “/t”) {
_root.brush.gotoandStop(“t”);
}
if (_root.brush._droptarget == “/fl”) {
_root.brush.gotoandStop(“fl”);
}
if (_root.brush._droptarget == “/pt”) {
_root.brush.gotoandStop(“pt”);
}
if (_root.brush._droptarget == “/m”) {
_root.brush.gotoandStop(“m”);
}
if (_root.brush._droptarget == “/ob”) {
_root.brush.gotoandStop(“ob”);
}
if (_root.brush._droptarget == “/rb”) {
_root.brush.gotoandStop(“rb”);
}
if (_root.brush._droptarget == “/bs”) {
_root.brush.gotoandStop(“bs”);
}
if (_root.brush._droptarget == “/r”) {
_root.brush.gotoandStop(“r”);
}
if (_root.brush._droptarget == “/pu”) {
_root.brush.gotoandStop(“pu”);
}
if (_root.brush._droptarget == “/o”) {
_root.brush.gotoandStop(“o”);
}
if (_root.brush._droptarget == “/pi”) {
_root.brush.gotoandStop(“pi”);
}
if (_root.brush._droptarget == “/br”) {
_root.brush.gotoandStop(“br”);
}
if (_root.brush._droptarget == “/w”) {
_root.brush.gotoandStop(“w”);
}
if (_root.brush._droptarget == “/y”) {
_root.brush.gotoandStop(“y”);
}
if (_root.brush._droptarget == “/nb”) {
_root.brush.gotoandStop(“nb”);
}
if (_root.brush._droptarget == “/a1”) {
_root.a1_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a2”) {
_root.a2_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a3”) {
_root.a3_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a4”) {
_root.a4_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a5”) {
_root.a5_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a6”) {
_root.a6_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a7”) {
_root.a7_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a8”) {
_root.a8_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a9”) {
_root.a9_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a10”) {
_root.a10_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a11”) {
_root.a11_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a12”) {
_root.a12_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a13”) {
_root.a13_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a14”) {
_root.a14_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a15”) {
_root.a15_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a16”) {
_root.a16_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a17”) {
_root.a17_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a18”) {
_root.a18_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a19”) {
_root.a19_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a20”) {
_root.a20_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a21”) {
_root.a21_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/a22”) {
_root.a22_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b1”) {
_root.b1_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b2”) {
_root.b2_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b3”) {
_root.b3_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b4”) {
_root.b4_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b5”) {
_root.b5_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b6”) {
_root.b6_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b7”) {
_root.b7_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b8”) {
_root.b8_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b9”) {
_root.b9_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b10”) {
_root.b10_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b11”) {
_root.b11_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b12”) {
_root.b12_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b13”) {
_root.b13_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b14”) {
_root.b14_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b15”) {
_root.b15_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b16”) {
_root.b16_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b17”) {
_root.b17_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b18”) {
_root.b18_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b19”) {
_root.b19_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b20”) {
_root.b20_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b21”) {
_root.b21_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/b22”) {
_root.b22_color.setRGB(0xFF8211);
}
if (_root.brush._droptarget == “/home”) {
tellTarget ("/") {
gotoAndStop (“Scene 1”, “home”);
}
}
}

Hello.

First I gotta warn you I’m not sure if this’ll work in F5, but it’s worth a shot, I guess.

For the first part of your code, for picking colours (I’m glad to see somebody else not using the American spelling), you can try the following (also keep in mind I haven’t actually tried this; it’s just off the top of my head, so there might be some simple syntax errors, sorry):


on (release) {
	stopDrag ();
	_root.brush.gotoandStop(_root.brush._droptarget._name);
}

This should work, with the droptarget name coming out as just “w”, for example. The only problem with this part that I see, is that if you drop on the “a1” or “b22” movie clips, the brush will attempt to go to the frame labeled “a1” or “b22”. I believe this will generate an error message, so you have to have a workaround (like a toggled variable that is local to the “a1” movie clip that identifies it as NOT a colour picker, so don’t gotoandstop).


I’m not 100% sure how to shorten the second part with all the "a1"s, but I think you can use the array access operators, “[” and “]”. I guess it might look something like this:


**replace all the **

if (_root.brush._droptarget == "/b22") {
_root.b22_color.setRGB(0xFF8211);
}

**blocks with just the single line**

_root[_root.brush._droptarget._name + "_color"].setRGB(0xFF8211);

The only problem I foresee with this part is that if the drop target is one of the “w” or “bs” movie clips, the script will attempt _root.w_color.setRGB(0xFF8211). This may lead to an error, or it may just be ignored, since I assume there is no “w_color” movie clip. It’s bad programming to leave such an error unaccounted for, but I’m sure you can find a workaround (like the local variable thing I mentioned).

Hope that helps.

-Al