Accessing Arrays w/ EventListener??
- Listening for a certain array value in order to change frames -
hello, it's me again
I am trying to implement this typewriter effect for my dialogues, but I don't know how to access the array in order to know when a conversation is over. Ideally I'd like to create a conversation/scene class, but for now I'm just trying to be able to get out of a conversation.
my main class is:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
// TEXT BOX CONSTRUCTOR
public function Main() {
var textBlocks:Array=new Array(["pic1","what's up?"],["pic3","oh!"],["pic3","nothing."],["pic4","I'm here too"],["pic2","me too"],["pic4","what should we do"],["pic3","nothing..."],["pic1","ok"]);
textBox.textBlocks=textBlocks;
textBox.startText();
}
}
}
//////////////////////////
my text box script is:
package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.media.Sound;
public class TextBox extends MovieClip {
private const CHARA:int=0;
private const TEXT:int=1;
private var _currentTextBlockIndex:int=0;
private var _currentTextBlock:String;
private var _textBlocks:Array;
// CONSTRUCTOR
public function TextBox() {
}
public function set textBlocks(txt:Array):void {
_textBlocks=txt;
}
public function startText():void {
_currentTextBlock=_textBlocks[_currentTextBlockIndex][TEXT];
characterIcon.gotoAndStop(_textBlocks[_currentTextBlockIndex][CHARA]);
addEventListener(Event.ENTER_FRAME, updateText);
addEventListener(MouseEvent.CLICK, fillText);
}
private function updateText(e:Event):void {
if (txt.text.length<_currentTextBlock.length) {
txt.text=_currentTextBlock.substr(0,txt.text.length+1);
} else {
removeEventListener(Event.ENTER_FRAME, updateText);
fillText();
}
}
private function fillText(e:MouseEvent = null):void {
txt.text=_currentTextBlock;
if (_currentTextBlockIndex<_textBlocks.length-1) {
addEventListener(MouseEvent.CLICK, nextTextBlock);
}
}
private function nextTextBlock(e:MouseEvent):void {
removeEventListener(MouseEvent.CLICK, nextTextBlock);
txt.text="";// clear the text
_currentTextBlockIndex++;
_currentTextBlock=_textBlocks[_currentTextBlockIndex][TEXT];// set the text
characterIcon.gotoAndStop(_textBlocks[_currentTextBlockIndex][CHARA]);// set the character icon
addEventListener(Event.ENTER_FRAME, updateText);// start updating the text
addEventListener(MouseEvent.CLICK, fillText);
}
}
}
//////////////////
From here, I thought I could do something like
private function endConvo(e:Event):void {
if (textBlocks[8]) {
removeEventListener(MouseEvent.CLICK, nextTextBlock);
addEventListener(MouseEvent.CLICK, nextConvo);
}
}
public function nextConvo(e:MouseEvent = null):void {
gotoAndStop("end");
}
so that at the end of the 8th array, which is the last array in the conversation, that i would remove the nextTextBlock event listener and put in one for going to the next frame, but it doesn't work. I'm still trying to get a hang on working outside of the timeline, and furthermore working with as3 instead of as2.
needless to say, the conversation upon ending will not go to the next frame.
thank you so much!!!!
