Actionscript 2 call function from variable

Posted by NebNeb on Stack Overflow See other posts from Stack Overflow or by NebNeb
Published on 2010-03-22T16:22:40Z Indexed on 2010/03/23 4:41 UTC
Read the original article Hit count: 195

Filed under:

How can i call a function form a variable.

var upfunction = init;
//or
var upfunction = init();

I have tried the above code and it does not work. I want to be able to call that variable from a keypress and change the variables function. For example.

function init(){
   //Do whatever
}

function init2(){
   //Do another thing
}

var upfunction = init();
if (Key.getCode() == Key.UP)
{
    upfunction;
} 

Then later doing

upfunction = init2();

That way i could change the function without having much code. Sorry if this is a noob question but all i do is copy and paste code i have found.

© Stack Overflow or respective owner

Related posts about actionscript-2