# Annoying handling of function pointers in AS3

**URL:** <https://forum.kirupa.com/t/annoying-handling-of-function-pointers-in-as3/315649>\
**Category:** flash\
**Created:** [October 31, 2010, 11:17pm UTC](https://forum.kirupa.com/t/annoying-handling-of-function-pointers-in-as3/315649 "2010-10-31T23:17:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [October 31, 2010, 11:17pm UTC](https://forum.kirupa.com/t/annoying-handling-of-function-pointers-in-as3/315649/1 "2010-10-31T23:17:50Z")

</div>

I’m not sure if you’ve noticed this, probably not, but function pointers in AS3 run much, much slower than calling the function directly.

It’s a recent finding, and an annoying one. I use function pointers a lot.

An obvious example would be to easily change the behaviour of a certain object.

Say I have a class that controls movement, it has a class level function variable called UPDATE (ie public var UPDATE:Function), and 3 or 4 actual functions it can point to.

This always me to quickly/easily change the behaviour of an object. Say for example I want an object to run on different movement code once it’s collided with something, I can just do UPDATE = movement2; etc.

However, a pointer for a function runs about 15 times slower than running the function directly, therefore I need a replacement.

And I really have no idea why there is this absurd disparity in speed between the 2. With some variables, accessing a reference is faster than accessing the variable directly, obviously not with functions.

What would you advise as a nice, simple replacement solution for the above example?

Cheers,  
RumbleSushi
