# Array decleration problem

**URL:** <https://forum.kirupa.com/t/array-decleration-problem/63250>\
**Category:** Uncategorized\
**Created:** [September 4, 2004, 10:07am UTC](https://forum.kirupa.com/t/array-decleration-problem/63250 "2004-09-04T10:07:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fightalone](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@fightalone](https://forum.kirupa.com/u/fightalone)\
**Post date:** [September 4, 2004, 10:07am UTC](https://forum.kirupa.com/t/array-decleration-problem/63250/1 "2004-09-04T10:07:49Z")

</div>

hi folks… i got problems with the following code… i’m used to code c++ so i’m quite unused to AS… is it possible to declare arrays like this:

```
aBgPic[11] = new Array;
 for(x=0; x&lt;=11; x++)
 {
     aBgPic[x] = "bg_pics/bg_pic" + x + ".jpg";
 }

```

this code doesnt work… could someone pls tell me an alternativ… or how to do it right…

thx in advance

yours

---

<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:** [September 4, 2004, 10:20am UTC](https://forum.kirupa.com/t/array-decleration-problem/63250/2 "2004-09-04T10:20:43Z")

</div>

```auto

aBgPic = new Array(11);
for(x=0; x<11; x++){
aBgPic[x] = "bg_pics/bg_pic" + x + ".jpg";
}

```

Specifying the length of the array in the constructor arguments (Array(11)) is possible, but not required, because arrays in AS are dynamic unlike arrays in C++. You can add elements and remove elements at will. Therefore, if you just create an empty array and use the for loop to write to elements 0 to 10, the array will extend to fit the 11 elements.

---

<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:** [September 4, 2004, 10:26am UTC](https://forum.kirupa.com/t/array-decleration-problem/63250/3 "2004-09-04T10:26:15Z")

</div>

> [@fightalone](#):
>
> hi folks… i got problems with the following code… i’m used to code c++ so i’m quite unused to AS… is it possible to declare arrays like this:
> 
> ```
> aBgPic[11] = new Array;
> for(x=0; x&lt;=11; x++)
> {
> aBgPic[x] = "bg_pics/bg_pic" + x + ".jpg";
> }
> 
> ```
> 
> this code doesnt work… could someone pls tell me an alternativ… or how to do it right…
> 
> thx in advance
> 
> yours

aBgPic = ;  
for (x=0; x\<=11; x++) {  
aBgPic = “bg\_pics/bg\_pic”+x+“.jpg”;  
}

or if you are deliberately making index11 of aBgPic an array  
aBgPic = ;  
aBgPic[11] = ;  
for (x=0; x\<=11; x++) {  
aBgPic[11] = “bg\_pics/bg\_pic”+x+“.jpg”;  
}

---

<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:** [September 4, 2004, 10:38am UTC](https://forum.kirupa.com/t/array-decleration-problem/63250/4 "2004-09-04T10:38:43Z")

</div>

thx for the replies folks…
