# F5 Is there a way to shorten this code please?

**URL:** <https://forum.kirupa.com/t/f5-is-there-a-way-to-shorten-this-code-please/8995>\
**Category:** flash\
**Created:** [December 2, 2002, 4:47pm UTC](https://forum.kirupa.com/t/f5-is-there-a-way-to-shorten-this-code-please/8995 "2002-12-02T16:47:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lmackenzie](https://avatars.discourse-cdn.com/v4/letter/l/f19dbf/32.png) [@Lmackenzie](https://forum.kirupa.com/u/Lmackenzie)\
**Post date:** [December 2, 2002, 4:47pm UTC](https://forum.kirupa.com/t/f5-is-there-a-way-to-shorten-this-code-please/8995/1 "2002-12-02T16:47:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 2, 2002, 6:16pm UTC](https://forum.kirupa.com/t/f5-is-there-a-way-to-shorten-this-code-please/8995/2 "2002-12-02T18:16:32Z")

</div>

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

```auto

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:

```auto

**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
