Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 10 of 10

Thread: string as function ?

  1. #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

  2. #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!

  3. #3
    1,596
    posts
    Holosuite User
    You 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

  4. #4
    Isn't this a perfect match for namespaces ?

  5. #5
    Code:
    var call:String='publicFunction';
    var param1:int=3;
    var param2:int=6;
    this[call](param1,param2);

  6. #6
    Thank you for your help guys, this is exactly what I needed

  7. #7
    Quote Originally Posted by sekasi View Post
    Isn't this a perfect match for namespaces ?
    You think so?

  8. #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.

  9. #9
    the object prior to [] (you're using this now) is the reference used to find the function you want to call. If abre_contacto is defined in 'this' then the above code is correct. Otherwise you need a reference to where abre_contacto really is.

  10. #10
    Quote Originally Posted by senocular View Post
    the object prior to [] (you're using this now) is the reference used to find the function you want to call. If abre_contacto is defined in 'this' then the above code is correct. Otherwise you need a reference to where abre_contacto really is.
    Yes, the code was right but the function name was wrong... thx anyway

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012