Dialogue in AS2

Alright, I’ve exhausted myself for a solid week trying to get something to work. But I can’t. I’ve tried forums and tutorials, but to no avail because I’m still stuck. I know how to do everything for my VERY basic game, but this one thing and it is holding up the creation process.

I’m surprised no one has ever had this issue before. If you ask me, it seems fairly common. But either someone made this fabulous tutorial somewhere that I have yet to see or I’m just too stupid to understand how this would work.

I’m creating a very linear game which will be dialogue-heavy. In fact, there will be little action involved at all. Think a game storybook. I’m using ActionScript 2 because AS3 is just too complicate for the type of newbie that I am. But all I’m trying to do is set up dialogue between two characters in my game with an image of the speaking character to the left of the textbox. Something very much like this:

I considered creating arrays for the dialogue (due to some thankful tips), but my problem is that if I create an array for every time two characters exchange three lines of dialogue, I would end up with over 300 arrays. Not my cup of tea.

So, instead, I focused on this. I created a function called speak. Speak pulls two parameters: charNum and charText. CharNum is a number which specifies which frame of the charPic instance should be displayed, showing which character is currently speaking. CharText is simply the dialogue the character will speak, which will be displayed in the dynamic textbox with variable name ‘dialogue’.

The following code is an example of what I have at home. I’m at work trying to get help, so I don’t have the actual coding. Therefore, small errors may be present. I’m looking more at the overall functions guiding my code.

function speak(charNum:Number,charText:String = “”) {

charText = dialogue;

if (charNum = 2) {
_root.charPic.gotoAndStop(2);
}

if (charNum = 3) {
_root.charPic.gotoAndStop(3);
}

if (Key.isDown(Key.SPACE)) {
dialogue = “”;
_root.charPic.gotoAndStop(1);
}
}
I’m sure you guys see the problem. But if you don’t, here’s an example of a horrible thing happening:

speak(2,“Hello world!”);
speak(3,“Hello back to you!”);
You see, AS2 sees these as I believe what is called synchronous functions, meaning they run at the same time. Therefore, the second speak function overwrites the first one before the user presses the space bar to go to the next one. See the issue?

I’ve tried to seek help on this issue (and other before), and I keep getting told about arrays and setInterval. But my problem is that I’ve tried it all. I don’t see a good array tutorial about this type of thing, and setInterval doesn’t function like I’d want as well. Instead, it seems that from what I’ve read and tried, setInterval is for setting a delay up for a certain amount of time. I don’t want that. I want a delay to occur until a button (namely the space bar) is pressed.

Like I said, this seems like a fairly common thing to do (stringing together dialogue in a flash movie/game), but I have seen no tutorial nor other help through all my Google and forum searching. A little push in the right direction would be appreciated. Like I said, I’ve figured out everything else my game needs from preloaders to game inventory to animation effects. I thought dialogue would be the easiest, but it what I’m stuck on.

Thanks in advance for any help to my problem.

(P.S. - If I ever get this problem solved, I will personally author a tutorial on the matter so that no one will be stuck on this kind of thing again without help.)