# Array of references rather than values

**URL:** <https://forum.kirupa.com/t/array-of-references-rather-than-values/633765>\
**Category:** flash\
**Created:** [September 14, 2015, 10:35pm UTC](https://forum.kirupa.com/t/array-of-references-rather-than-values/633765 "2015-09-14T22:35:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlpann](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@tlpann](https://forum.kirupa.com/u/tlpann)\
**Post date:** [September 14, 2015, 10:35pm UTC](https://forum.kirupa.com/t/array-of-references-rather-than-values/633765/1 "2015-09-14T22:35:58Z")

</div>

Krinlon, you answered my previous question about arrays by showing how to get a reference to a variable out of an array, rather than its value. I did not understand your answer so I’m going to ask a more specific question and see if you can fill in the blanks for me.

Consider the following:

```
var incr:int = 0;
var arr:Array = [myFunction, getArgument];
function myFunction(arg):int {
     return arg;
}
function getArgument():int {
     return incr++;
}
trace(arr[0](arr[1])); // 0
trace(arr[0](arr[1])); // 0
trace(arr[0](arr[1])); // 0

```

I understand this happens because the second element of arr is simply a reference to the value returned by getArgument at the time the array is created. (Is that the best way to say that?)

But I want getArgument to be executed every time, so that::

```
trace(arr[0](arr[1])); // 0
trace(arr[0](arr[1])); // 1
trace(arr[0](arr[1])); // 2

```

How do I do that?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [September 14, 2015, 10:44pm UTC](https://forum.kirupa.com/t/array-of-references-rather-than-values/633765/2 "2015-09-14T22:44:37Z")

</div>

> [@tlpann](#):
>
> I understand this happens because the second element of arr is simply a reference to the value returned by getArgument at the time the array is created.

Nope. Its happening because you’re passing in arr[1] to the function call of myFunction (as arr[0]) which resolves to the getArgument function itself, not what you get when you call getArgument. And that is getting coerced into an int because that’s what you specified as the return value. What you want to be doing is

```auto
trace(arr[0]( arr[1]() ));

```

which will get you what you want (note the added parens given to arr[1] so its being called).

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [September 15, 2015, 1:13am UTC](https://forum.kirupa.com/t/array-of-references-rather-than-values/633765/3 "2015-09-15T01:13:02Z")

</div>

senocular’s pretty much got this covered, I think.

> [@tlpann](#):
>
> I did not understand your answer so I’m going to ask a more specific question and see if you can fill in the blanks for me.

Sorry. Sometimes it’s really hard to map other people’s use of terminology with my own understanding of it.
