/ Published in: ActionScript 3
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 /** * ActionScript 3 Call a Function by String Representation of Function Name * * This will allow you to execute a function if you only have the function name * as a string. The compiler won't catch any issues with this, so be careful with * it. However, it can save a lot of time and code if used correctly. * * The first argument to "apply" is the object that the function should apply to * The second argument is an Array object of arguments to pass to the function */ var functionName:String = "myFunction"; var containerObject:Object = myContainerObject; if (containerObject.hasOwnProperty(functionName)) containerObject[functionName].apply(null, [ args ]); else trace("Cannot call function: " + functionName + " does not exist in " + containerObject.id);
Comments
                    Subscribe to comments
                
                