Flash Variables

N2o)

Retired.
Reaction score
51
Just a quick question:

Can I store a function within a variable and array, so i can call it back later with it arguments.
e.g.

Code:
function func_Hiya(Name) {
trace(Name);
}
var Test = new Array(func_Hiya(),func_Lol());
Test[0]("N2o");

I assume i can ask this here.
 
Reaction score
333
Yes you can. You don't call the function to get the reference, though, you simply refer to its name.

Code:
[COLOR="Blue"]function[/COLOR] Test(str:[COLOR="Blue"]String[/COLOR]) {
    [COLOR="Blue"]trace[/COLOR](str)
}

Blah = [COLOR="Blue"]new Array[/COLOR](Test)
Blah[0]([COLOR="Green"]"test"[/COLOR])

Above code should (I don't have flash open at the moment) work in ActionScript 1.0 and 2.0.

In ActionScript 3.0, you can only store the reference for anonymous functions:

Code:
[COLOR="Blue"]var[/COLOR] Test:[COLOR="Blue"]Function[/COLOR] = [COLOR="Blue"]function[/COLOR] (str:[COLOR="Blue"]String[/COLOR]) {
    [COLOR="Blue"]trace[/COLOR](str)
}

[COLOR="Blue"]var[/COLOR] Blah:[COLOR="Blue"]Array[/COLOR] = [COLOR="Blue"]new Array[/COLOR](Test)
Blah[0]([COLOR="Green"]"test"[/COLOR])

Above should work in ActionScript 3.0.
 

N2o)

Retired.
Reaction score
51
Does this only work for 1 argument or could i use it for more than 1? so could func_example2(whichString,whichNumber,whichBoolean) be stored the same as the one you mentioned above.

edit: btw i'm using Actionscript 2.0
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top