Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Accessing Arrays w/ EventListener??

Community Beginner ,
Aug 21, 2015 Aug 21, 2015

- 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!!!!

TOPICS
ActionScript
358
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 21, 2015 Aug 21, 2015

It is a bit hard for me to decipher, but it looks like you might be adding the same listeners multiple times, and never removing them when you add the next.  You should see about limiting adding them only once or remove them when another should be working.

As far as ending and getting to the next convo, I think it would require something along the lines of changing your fillText function

  private function fillText(e:MouseEvent = null):void {

       txt.text=_currentTextBlock;

       if (_currentTextBlockIndex<_textBlocks.length-1) {

           addEventListener(MouseEvent.CLICK, nextTextBlock);

       } else {

           endConvo();   // remove the evt:Event argument from that function

       }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 22, 2015 Aug 22, 2015
LATEST

Thank you! Though now it says

else {

endConvo();

}

Gives me the error "1136 incorrect number of arguments"

??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines