# Associative Arrays and For loops

**URL:** <https://forum.kirupa.com/t/associative-arrays-and-for-loops/327374>\
**Category:** flash\
**Created:** [February 25, 2012, 12:02pm UTC](https://forum.kirupa.com/t/associative-arrays-and-for-loops/327374 "2012-02-25T12:02:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheOtherTedium](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@TheOtherTedium](https://forum.kirupa.com/u/TheOtherTedium)\
**Post date:** [February 25, 2012, 12:02pm UTC](https://forum.kirupa.com/t/associative-arrays-and-for-loops/327374/1 "2012-02-25T12:02:29Z")

</div>

I was trying something out, and came across a little error. I wrote the following code to create an array and, using each value of that array, create an associative array for the values of xVelocity and yVelocity. Check it out:

```php

var shrap:Array;
for (var i:uint = 0; i < 9; i++){ shrap* = "shrap" + i; var (shrap*):Object = new Object(); shrap*.yVelocity = Math.random() * 10 - 5; shrap*.xVelocity = Math.random() * 10 - 5;}

```

Once I got a conversion to string error, I also tried:

```php

var shrap:Array;var iName:Array;
for (var i:uint = 0; i < 9; i++){ iName* = i.toString(); shrap* = "shrap" + iName; var (shrap*):Object = new Object(); shrap*.yVelocity = Math.random() * 10 - 5; shrap*.xVelocity = Math.random() * 10 - 5;}

```

But I get an error from that as well. I think I understand basically why this doesn’t work, but I’m wondering if, given the spirit of what I’m trying to do, **you** can think of a working alternative.

Thanks!
