AS3 Converting a String to a Function name


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // you might want to call a function but you have the function name as a string, this is how to do it
  2. // Create new :Function var and give it the string using this[]
  3.  
  4. for(i=0; i<4; i++)
  5. {
  6. var funcName:Function = this["func"+i];
  7. funcName(param1, param2);
  8. }
  9.  
  10. function func0(p1, p2)
  11. {
  12.  
  13. }
  14.  
  15. function func1(p1, p2)
  16. {
  17.  
  18. }
  19.  
  20. function func2(p1, p2)
  21. {
  22.  
  23. }
  24.  
  25. function func3(p1, p2)
  26. {
  27.  
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.