A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Function object

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    3

    Function object

    So eval() in Flash doesn't work the same as in JavaScript. Fair enough. Can someone please explain to me why the following code doesn't work in Flash (MX)?

    PHP Code:
    var executors = [];
    function 
    exec(funcargs) {
        if (!
    executors[args.length]) {
            var 
    bodya;

            
    body "return func(";

            for (
    args.length ; ++a) {
                if (
    0)
                    
    body += ", ";

                
    body += "args[" "]";
            }

            
    body += ")";

            
    executors[args.length] = new Function("func""args"body);
        }

        
    executors[args.length](funcargs);
    }

    function 
    testFunc(msg1msg2) {
        
    trace("msg1: " msg1 "; msg2: " msg2);
    }

    exec(testFunc,["foo","bar"]); 
    That code should write "msg1: foo; msg2: bar" to the message window. Instead it just sits there and kind of fiddles with its hair. My guess is that the parser won't interpret the function body.

    Any ideas on why this doesn't work in AS, but does in JS?

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    you cant create new functions in flash with the new keyword and the function object as a constructor (at least not that Im aware of)... what it seems like you are trying to do is already available to you through the apply method:

    testFunc.apply(null, ["foo","bar"]);

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center