# Need help creating a loop

**URL:** <https://forum.kirupa.com/t/need-help-creating-a-loop/225482>\
**Category:** Uncategorized\
**Created:** [May 12, 2007, 12:47pm UTC](https://forum.kirupa.com/t/need-help-creating-a-loop/225482 "2007-05-12T12:47:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyryan](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@andyryan](https://forum.kirupa.com/u/andyryan)\
**Post date:** [May 12, 2007, 12:47pm UTC](https://forum.kirupa.com/t/need-help-creating-a-loop/225482/1 "2007-05-12T12:47:51Z")

</div>

Hi, i posted this thread recently on this board but only ended up with half a solution. Duncanhall helped me out big time but we never quite solved the problem:

Duncanhall helped me create a script that when a button is pressed, fades in a white box…loads a new jpeg in a container clip underneath the white box…and when that is finished loading…the white box fades out again…revealing the image. I am basically creating photogallery with this effect. I know there are tutorials that do this with xml etc. but i was hoping to do something from scratch without xml if poss. ANYWAY the script worked fine but what i now need to do is, rather than apply this code to every button, set up a script that can perform the same action every time but just replace the image.ID with the corresponding button number. ANY IDEAS? below is the original script:

[FONT=Courier New][LEFT][COLOR=#808080]_//IMPORTS_[/COLOR]  
[COLOR=#0000ff]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]Tween[/COLOR];  
[COLOR=#0000ff]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR]._;  
[COLOR=#808080]_//VARS\*[/COLOR]  
[COLOR=#000000] **var** [/COLOR] button\_[COLOR=#000080]1[/COLOR]_tween:[COLOR=#0000ff]Object[/COLOR];  
[COLOR=#000000] **var** [/COLOR] container\_mcl:[COLOR=#0000ff]MovieClipLoader[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000ff]MovieClipLoader[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] mcl\_listener:[COLOR=#0000ff]Object[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000ff]Object[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#808080]//EVENTS[/COLOR]  
button_[COLOR=#000080]1[/COLOR].[COLOR=#0000ff]onRelease[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR]:V[COLOR=#0000ff]oid[/COLOR] [COLOR=#000000]{[/COLOR]  
button\_[COLOR=#000080]1[/COLOR]\_tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]white\_block[/COLOR], [COLOR=#ff0000]“_alpha"[/COLOR], Strong.[COLOR=#000080]easeInOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]30[/COLOR], [COLOR=#000000] **false** [/COLOR][COLOR=#000000])[/COLOR];  
button_[COLOR=#000080]1[/COLOR]\_tween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
load\_external\_imageCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
mcl\_listener.[COLOR=#0000ff]onLoadProgress[/COLOR] = [COLOR=#000000] **function** [/COLOR][COLOR=#000000]([/COLOR]target\_mc:[COLOR=#0000ff]MovieClip[/COLOR], loadedBytes:[COLOR=#0000ff]Number[/COLOR], totalBytes:[COLOR=#0000ff]Number[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] percentage:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]round[/COLOR][COLOR=#000000]([/COLOR]COLOR=#000000[/COLOR] \* [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#0000ff]trace[/COLOR] [COLOR=#000000]([/COLOR]percentage + [COLOR=#ff0000]”% loaded"[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]

mcl\_listener.[COLOR=#0000ff]onLoadComplete[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
button\_[COLOR=#000080]1[/COLOR]\_tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]target\_mc.[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]white\_block[/COLOR], [COLOR=#ff0000]"\_alpha"[/COLOR], Strong.[COLOR=#000080]easeInOut[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]30[/COLOR], [COLOR=#000000] **false** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_//FUNCS_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] load\_external\_imageCOLOR=#000000[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
container\_mcl.[COLOR=#0000ff]loadClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“yourExternalImage.jpg”[/COLOR], container\_mc[COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//RUN!_[/COLOR]  
white\_block.[COLOR=#0000ff]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
container\_mcl.[COLOR=#0000ff]addListener[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000ff]stop[/COLOR]COLOR=#000000[/COLOR];  
[/LEFT]  
[/FONT]

and here is the loop script duncanhall came up with…but however many traces i used i couldnt find the problems or make it work!:

you could try something like this:

ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#808080]_/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
IMPORTS  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/_[/COLOR]  
[COLOR=#0000ff]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]Tween[/COLOR];  
[COLOR=#0000ff]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR]._;  
[COLOR=#808080]_/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
VARS  
_**/[/COLOR]  
[COLOR=#000000]var[/COLOR] button\_tween:[COLOR=#0000ff]Object[/COLOR];  
[COLOR=#000000]var[/COLOR] container\_mcl:[COLOR=#0000ff]MovieClipLoader[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]MovieClipLoader[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]var[/COLOR] mcl\_listener:[COLOR=#0000ff]Object[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Object[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]var[/COLOR] number\_of\_images:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]50[/COLOR];  
[COLOR=#808080]/**_  
EVENTS  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*[/COLOR]  
mcl\_listener.[COLOR=#0000ff]onLoadProgress[/COLOR] = [COLOR=#000000] **function** [/COLOR][COLOR=#000000]([/COLOR]target\_mc:[COLOR=#0000ff]MovieClip[/COLOR], loadedBytes:[COLOR=#0000ff]Number[/COLOR], totalBytes:[COLOR=#0000ff]Number[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] percentage:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]round[/COLOR][COLOR=#000000]([/COLOR]COLOR=#000000[/COLOR] \* [COLOR=#000080]100[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#0000ff]trace[/COLOR] [COLOR=#000000]([/COLOR]percentage + [COLOR=#ff0000]"% loaded"[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]

mcl\_listener.[COLOR=#0000ff]onLoadComplete[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
button\_tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]target\_mc.[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]white\_block[/COLOR], [COLOR=#ff0000]“_alpha"[/COLOR], Strong.[COLOR=#000080]easeInOut[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]30[/COLOR], [COLOR=#000000] **false** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
FUNCS  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/[/COLOR]  
[COLOR=#000000] **function** [/COLOR] initiate\_button\_eventsCOLOR=#000000[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]for[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i:[COLOR=#0000ff]Number[/COLOR]=[COLOR=#000080]0[/COLOR]; i\<number\_of\_images; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] targetButton\_mc:[COLOR=#0000ff]MovieClip[/COLOR] = [COLOR=#0000ff]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#ff0000]"button_”[/COLOR]+i[COLOR=#000000]][/COLOR];  
targetButton.[COLOR=#000080]imageID[/COLOR] = i;  
targetButton\_mc.[COLOR=#0000ff]onRelease[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR]:V[COLOR=#0000ff]oid[/COLOR] [COLOR=#000000]{[/COLOR]  
button\_tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]white\_block[/COLOR], [COLOR=#ff0000]"\_alpha"[/COLOR], Strong.[COLOR=#000080]easeInOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]30[/COLOR], [COLOR=#000000] **false** [/COLOR][COLOR=#000000])[/COLOR];  
button\_tween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] image\_to\_load:[COLOR=#0000ff]String[/COLOR] = [COLOR=#ff0000]“image”[/COLOR]+[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]obj[/COLOR].[COLOR=#000080]imageID[/COLOR]+[COLOR=#ff0000]".jpg"[/COLOR];  
[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]obj[/COLOR].[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]container\_mcl[/COLOR].[COLOR=#0000ff]loadClip[/COLOR][COLOR=#000000]([/COLOR]image\_to\_load, [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]obj[/COLOR].[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]container\_mc[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
RUN, \*\*\*\*\*!  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/_[/COLOR]  
white\_block.[COLOR=#0000ff]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
container\_mcl.[COLOR=#0000ff]addListener[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000ff]stop[/COLOR]COLOR=#000000[/COLOR];  
[/LEFT]  
[/FONT]
