# For

**URL:** <https://forum.kirupa.com/t/for/20203>\
**Category:** Uncategorized\
**Created:** [May 6, 2003, 12:44pm UTC](https://forum.kirupa.com/t/for/20203 "2003-05-06T12:44:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuXtA](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@JuXtA](https://forum.kirupa.com/u/JuXtA)\
**Post date:** [May 6, 2003, 12:44pm UTC](https://forum.kirupa.com/t/for/20203/1 "2003-05-06T12:44:59Z")

</div>

I tried to shroten my code using a for statement but cant get it to exactly work when trying to use it with buttons…

[AS]  
lnk0.onRelease = function() {  
boxb.\_x = \_root.lnk0.\_x;  
\_root.moviplay = “1”;  
};  
lnk1.onRelease = function() {  
boxb.\_x = \_root.lnk1.\_x;  
\_root.moviplay= “4”;  
\_root.flag = 1;  
};  
lnk2.onRelease = function() {  
boxb.\_x = \_root.lnk2.\_x;  
\_root.moviplay = “7”;  
};

[/AS]

too  
[AS]  
framenum = new array(“1”, “4”, “7”)

for (j=0; j\<3; j++) {  
[“lnk”+j].onRelease = function() {  
boxb.\_x = \_root[“lnk”+j].\_x;  
\_root.moviplay = framenum[j];  
};  
}  
[/AS]

---

<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:** [May 6, 2003, 4:27pm UTC](https://forum.kirupa.com/t/for/20203/2 "2003-05-06T16:27:59Z")

</div>

[“lnk”+j] won’t work.

If the code is on the same timeline as the clips use this[“lnk”+j] (that way its loadMovie compatible).

Also… inside the onRelease you have \_root[“lnk”+j], you don’t need that, you can replace it with “this” (as in this.\_x).

Should work.

---

<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:** [May 6, 2003, 10:06pm UTC](https://forum.kirupa.com/t/for/20203/3 "2003-05-06T22:06:25Z")

</div>

yeah, now you can load the swf into a MovieClip and the onRelease handler will be assigned to the Buttons/MovieClips.

however, there’s a problem…

```auto
_root.moviplay = framenum[j];

```

you’ll need to change that line to:

```auto
this._parent.moviplay = framenum[j];

```

but there’s still one problem… 😛

the value of the variable j, will be 3 after the script is executed, therefore framenum[j] will return undefined.

you have to save the value of j in a variable of each Button/MovieClip:

```auto
for (j=0; j<3; j++) {
this["lnk"+j].j = j;
}

```

in the end, you’d have this script:

```auto
framenum = new array("1", "4", "7");
for (j=0; j<3; j++) {
	this["lnk"+j].j = j;
	this["lnk"+j].onRelease = function() {
		boxb._x = this._x;
		this._parent.moviplay = framenum[this.j];
	};
}

```

=)

---

<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:** [May 6, 2003, 10:29pm UTC](https://forum.kirupa.com/t/for/20203/4 "2003-05-06T22:29:06Z")

</div>

Very good catch… I didn’t examine that closely.

But I think I should take a break from the forum. My lack of ability to code recently is dampering my reputation on the forum… and giving me a headache as well… sigh… I can’t wait to get out of this funk ☹

---

<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:** [May 6, 2003, 10:37pm UTC](https://forum.kirupa.com/t/for/20203/5 "2003-05-06T22:37:32Z")

</div>

nah… you will always be my hero. :love:

seriously, i agree with you, you need a break.  
suddenly without a notice you’ll be coding like keith peters. 😉

---

<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:** [May 6, 2003, 10:37pm UTC](https://forum.kirupa.com/t/for/20203/6 "2003-05-06T22:37:35Z")

</div>

> _Originally posted by senocular_  
> \*\*lostinbeta is AWESOME and really knows his stuff! \*\*  
> ^ I hear the guy who said that knows what hes talking about to and can be trusted 😉

---

<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:** [May 6, 2003, 10:47pm UTC](https://forum.kirupa.com/t/for/20203/7 "2003-05-06T22:47:47Z")

</div>

LOL… thanks Kax and Sen… but seriously, I agree with what kax seriously agrees with about what I said… I just need to take a break… i’m fried right now :hangover:

But anywho… no more thread hijacking and just a lame attempt to get this back on course…

[AS]framenum = new array(“1”, “4”, “7”);[/AS]

Can also be written as…

[AS]framenum = [“1”, “4”, “7”];[/AS]

[edit]removed some stuff because I was being stupid[/edit]

---

<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:** [May 6, 2003, 10:52pm UTC](https://forum.kirupa.com/t/for/20203/8 "2003-05-06T22:52:34Z")

</div>

ok well we need to think of a good quick rehab for lost because I know I cant make up for his lost time! Who can handle that much slack? No one!

how about a 5 min hot shower… with Mr Bubbles… and a rubber ducky… That should do it, right?

---

<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:** [May 6, 2003, 10:56pm UTC](https://forum.kirupa.com/t/for/20203/9 "2003-05-06T22:56:14Z")

</div>

with mr bubbles and a rubber ducky!? 😛

yeah… that could work too. 😛

---

<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:** [May 6, 2003, 11:28pm UTC](https://forum.kirupa.com/t/for/20203/10 "2003-05-06T23:28:43Z")

</div>

I don’t have any Mr. Bubbles and my rubber ducky drowndeded :(…lol. I think I just need a bit off from AS then when I come back just head first right back into it and try to learn something new in it. I want to get some books on AS too, but thats not going to happen for a while, so I mostly just gotta go from experimentation.

---

<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:** [May 7, 2003, 9:48am UTC](https://forum.kirupa.com/t/for/20203/11 "2003-05-07T09:48:14Z")

</div>

thanks lost and kax for fixing my mistakes

And lost, I wish I was half as good as you are in AS… but then again I suck

---

<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:** [May 7, 2003, 9:49am UTC](https://forum.kirupa.com/t/for/20203/12 "2003-05-07T09:49:59Z")

</div>

no problem, JuXtA. =)

---

<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:** [May 7, 2003, 5:50pm UTC](https://forum.kirupa.com/t/for/20203/13 "2003-05-07T17:50:01Z")

</div>

no problem JuXtA 🙂
