-1

Is it possible to wrap a variable-length-arguments function in Actionscript?

I tried

    private function getString (name:String, ...args):String {
        return var_arg_function(name,args);
    }

but it didn't work since sprintf was called with just 1 extra argument, i.e. the Array args.

o0'.
  • 11,739
  • 19
  • 60
  • 87
  • 1
    What is it exactly that you are trying to achieve? sprintf is not native to AS3 to begin with and the pseudocode you provide looks a bit like an infinite loop – Dennis Jaamann Jun 09 '11 at 15:04
  • That's not pseudo-code, that's real code that works except for the args part. It's not recursive. I'll clarify. – o0'. Jun 09 '11 at 15:09

2 Answers2

3

I'm not aware of sprintf in AS3, but perhaps you're using a custom function... Try using Function.apply. I haven't tested this, but something like:

private function getString(name:String, ...args):String {
     return sprintf.apply(this, [xxx.getString(name)].concat(args));
}
Corey
  • 5,818
  • 2
  • 24
  • 37
0

sprintf does not exist in as3 - check out this thread

Community
  • 1
  • 1
Bosworth99
  • 4,206
  • 5
  • 37
  • 52
  • However, this does not answer the question. – o0'. Jun 09 '11 at 15:12
  • 1
    @Lo'oris Do not -1 for something you did not specify thoroughly enough. He is correct to say that sprintf does not exist in AS3. By just looking at your code there was no way of knowing you were using a custom written function. – Dennis Jaamann Jun 09 '11 at 15:28
  • 1
    Well w/e - glad you got it worked out @Lo'oris. & thx @Dennis. – Bosworth99 Jun 09 '11 at 15:32
  • 1
    @Dennis: the question might have been unclear, but it was clear that I was asking for something unrelated to this answer, sorry. (nothing personal @Bosworth, of course!) ... edit: it might have been appropriate for a comment, instead. – o0'. Jun 09 '11 at 16:08
  • 1
    @Lo'oris - no offense taken ;) and your right - it probably should of been a comment. Cheers – Bosworth99 Jun 09 '11 at 16:14