# How do I put functions into arrays?

**URL:** <https://forum.kirupa.com/t/how-do-i-put-functions-into-arrays/316962>\
**Category:** flash\
**Created:** [December 7, 2010, 12:07am UTC](https://forum.kirupa.com/t/how-do-i-put-functions-into-arrays/316962 "2010-12-07T00:07:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomii01](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@tomii01](https://forum.kirupa.com/u/tomii01)\
**Post date:** [December 7, 2010, 12:07am UTC](https://forum.kirupa.com/t/how-do-i-put-functions-into-arrays/316962/1 "2010-12-07T00:07:50Z")

</div>

Like the title says, I would appreciate if someone could show me how to do this.

I tried to do it, but I don’t quite understand how it works.  
When I experimented with it, I tried to push one string and one function named “moveRight” into the array,

```auto

_behaviours.push("1", moveRight);
trace("_behaviours: " +_behaviours);

```

but when I trace the content of the array, I get

```auto

_behaviours: 1,function Function() {}

```

why is my function moveRight, being renamed to “Function”, and how do I call the different functions if I have several of them in one array?

The purpose of all this is to make a simple AI system for my game enemies. After the enemies are added to stage, a special function would calculate a random number based on the number of entries in the array and then make the enemy perform the chosen function.

Thanks in advance!
