|
-
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.
-
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);
}
-
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]]();
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|