A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Array of Functions - How To Call?

Hybrid View

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    123

    Array of Functions - How To Call?

    I've done this before, but can't find the previous file I did it in. Basically I have an array of functions, and I'm running an enter frame which calls these functions at certain times. The code's pretty basic so you can probably just view that to see what's going on. The problems are, my functions aren't occuring, although they're tracing out correctly.

    Code:
    var actionArray:Array = new Array([firstQuote, 20], [secondQuote, 40]);
    var actionCounter:Number = 0;
    
    this.onEnterFrame = function() {
    	for (var i:Number = 0; i<actionArray.length; i++) {
    		if (actionCounter == actionArray[i][1]) {
    			trace("HIT ACTION: "+actionArray[i][0]);
    			actionArray[i][0]();
    		}
    	}
    	actionCounter++;
    };
    
    //
    function firstQuote():Void {
    	this.first_quote.text.gotoAndPlay(2);
    	this.first_quote.mirror.gotoAndPlay(2);
    }
    function secondQuote():Void {
    	this.second_quote.text.gotoAndPlay(2);
    	this.second_quote.mirror.gotoAndPlay(2);
    }
    What am I missing here?

    Thanks in advance.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var actionArray:Array = new Array([firstQuote, 20], [secondQuote, 40]);
    var actionCounter:Number = 0;
    
    this.onEnterFrame = function() {
    	for (var i:Number = 0; i<actionArray.length; i++) {
    		if (actionCounter == actionArray[i][1]) {
    			trace("HIT ACTION: "+actionArray[i][0]);
    			this[actionArray[i][0]()];
    		}
    	}
    	actionCounter++;
    };
    
    //
    function firstQuote():Void {
    	trace("first")
    	this.first_quote.text.gotoAndPlay(2);
    	this.first_quote.mirror.gotoAndPlay(2);
    }
    function secondQuote():Void {
    	trace("second")
    	this.second_quote.text.gotoAndPlay(2);
    	this.second_quote.mirror.gotoAndPlay(2);
    }

  3. #3
    Senior Member
    Join Date
    Oct 2000
    Posts
    123
    Hmm, not working for me. I wish I could find where I've done it previously. Seems to me like it should be working.

    I tried:
    this[actionArray[i][0]()];

    Also tried:
    this[actionArray[i][0]]();

  4. #4
    Senior Member
    Join Date
    Oct 2000
    Posts
    123
    Got it:

    Code:
    var actionArray:Array = new Array(["firstQuote", 20], ["secondQuote", 40]);
    var actionCounter:Number = 0;
    
    this.onEnterFrame = function() {
    	for (var i:Number = 0; i<actionArray.length; i++) {
    		if (actionCounter == actionArray[i][1]) {
    			trace("HIT ACTION: "+actionArray[i][0]);
    			this[actionArray[i][0]]();
    		}
    	}
    	actionCounter++;
    };
    
    //
    function firstQuote():Void {
    	trace("first")
    	this.first_quote.text.gotoAndPlay(2);
    	this.first_quote.mirror.gotoAndPlay(2);
    }
    function secondQuote():Void {
    	trace("second")
    	this.second_quote.text.gotoAndPlay(2);
    	this.second_quote.mirror.gotoAndPlay(2);
    }

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