dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: ┐function array?

  1. #1
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    ┐function array?

    Hola.
    I am attempting to call my button onPress functions through an array. I am having no luck. Is it possible? Here is my script thus far:

    code:

    arrows = new Array("left_mc", "right_mc", "up_mc", "down_mc");
    arrowFuncs = new Array("leftFunk();", "rightFunk();", "upFunk();", "downFunk();");
    leftFunk = function () {
    trace("this is left");
    };
    rightFunk = function () {
    trace("this is right");
    };
    upFunk = function () {
    trace("this is up");
    };
    downFunk = function () {
    trace("this is down");
    };

    for (i=0; i<arrows.length; i++) {
    btn = eval(arrows[i]);
    btn.i = i;
    btn.onPress = function() {
    trace(arrowFuncs[this.i]);
    eval(arrowFuncs[this.i]);
    };
    }



    In this version of the script the correct function name is onPress traced, but the trace inside the called funtion is not.... that might not make much sense. Let me know if this is gibberish... or if you have an answer, comment, rude spiteful attack, link to the full version of the Rubber Johnny vid or whatever you come up with.

    Thanks in advance,
    1M.

  2. #2
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    simplified script

    here is the simplified script:

    code:

    arrowFuncs = new Array('leftFunk();');
    leftFunk = function () {
    trace("this is left");
    };
    left_mc.onPress = function() {
    eval(arrowFuncs[0]);
    };



    I can not get the leftFunk trace to the output window! Anyone have any advice.

    Thanks again,
    1M.

  3. #3
    Actionscript Developer KigD's Avatar
    Join Date
    Jan 2003
    Location
    georgia
    Posts
    597
    Ooo, heh, I see what you're trying to do.

    Try this:
    Function f1:Function = leftFunk;
    var myA:Array = new Array(f1);

    myA[0].call(this,(potential parameters seperated by commas));

    -Danny
    K2xL - My games, tutorials, message boards, and experiments.
    Blog

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