The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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