# Coding array and function

**URL:** <https://forum.kirupa.com/t/coding-array-and-function/168366>\
**Category:** flash\
**Created:** [November 6, 2005, 4:30pm UTC](https://forum.kirupa.com/t/coding-array-and-function/168366 "2005-11-06T16:30:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![onsitus](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/onsitus/32/971_2.png) [@onsitus](https://forum.kirupa.com/u/onsitus)\
**Post date:** [November 6, 2005, 4:30pm UTC](https://forum.kirupa.com/t/coding-array-and-function/168366/1 "2005-11-06T16:30:37Z")

</div>

This code works fine for loading a pic into a created container and placed centered in a box\_mc.  
I am trying with no luck to have the same thing repeat itself x number of time.  
My idea is:  
array=[1, 2, 3];  
var a = 0;  
if (a\< array.length){ a++;}  
then apply the underneath code until a = array.length  
changing all the 1 with the value of a, so to load each pic1,2 and 3 in different box\_mc1, 2, 3 (still being centered).  
:d:

```auto

[left]createEmptyMovieClip("container1", 1);[/left]
[left]function preload1(pic1) {[/left]
[left] loaded = pic1.getBytesLoaded();[/left]
[left] total = pic1.getBytesTotal();[/left]
[left] if (loaded>=total && loaded>0) {[/left]
[left] clearInterval(myinterval1);[/left]
[left] w1 = pic1._width;[/left]
[left] h1 = pic1._height;[/left]
[left] trace(w1);[/left]
[left] trace(h1);[/left]
[left] container1._x = box_mc1._x+(box_mc1._width-w1)/2;[/left]
[left] container1._y = box_mc1._y+(box_mc1._height-h1)/2;[/left]
[left] }[/left]
[left]}[/left]
[left]loadMovie("pic1.jpg", "container1");[/left]
[left]myinterval1 = setInterval(preload1, 50, container1);

```

[/left]

PS:I did read many post about XML but would like to stick to AS. I am trying to learn one thing at the time.:to:  
Thank you.
