Results 1 to 10 of 10
Thread: string as function ?
-
August 26th, 2008, 05:06 AM #1
string as function ?
Hello!
I have an XML for the items on a menu. I'd like each item call a different function, and have the function name written on the xml.
How would you approach this? Something like (my_str as function) or maybe using eval??
Regards
Pier
-
August 26th, 2008, 05:58 AM #2
After investigating a bit I've found that eval no longer exists in AS3... so for now I'll have to do an ugly switch/case... :S
If anybody knows a better way, please tell me!
-
August 26th, 2008, 06:29 AM #31,596Holosuite User
postsYou can always call functions by names like this: functionOwnerObject["functionName"](function arguments).
There's also a Deval library for AS3 here: http://riaone.com/products/deval/index.html
But for the task like the one you have you'd hardly need it
I support FlashDevelop (the .NET open source editor for Flash and web developers)
couchsurfing if you need it
-
August 26th, 2008, 06:33 AM #4
Isn't this a perfect match for namespaces ?
* [ Flash portfolio ] http://www.erikhallander.com/
* [ Flash blog ] http://www.erikhallander.com/blog/
* [ Work @ ] http://www.visualjazz.com.au
-
August 26th, 2008, 06:39 AM #5Code:
var call:String='publicFunction'; var param1:int=3; var param2:int=6; this[call](param1,param2);
-
August 26th, 2008, 10:38 AM #6
Thank you for your help guys, this is exactly what I needed
-
August 26th, 2008, 10:41 AM #7
-
August 26th, 2008, 10:45 AM #8
omg I thought that would be easy...

Tried it but this is what I get
ReferenceError: Error #1069: Property abre_contacto not found on master and there is no default value.
abre_contacto being the function I want to call, and master the name of the document class.
Code:var nombre_funcion:String = "abre_contacto"; this[nombre_funcion]();
edited: sorry, I mismatched the name of the function..... I need some more cofee... thanks anyway!
Last edited by Pier25; August 26th, 2008 at 10:57 AM.
-
August 26th, 2008, 10:49 AM #9
-
August 26th, 2008, 01:02 PM #10

Reply With Quote




Bookmarks