ObjectiveC-InLearning
ObjectiveC-InLearning

Reputation: 441

AS3 Flash Builder Dialog Text Showing

After doing some reading, I've learned that multithreading is not possible in AS3, and I still can't get my head wrapped around the idea of "faking it". However, I'm working on creating a dialog conversation between two characters and thought about a way to do it that I'm a little skeptical about. So correct me if it's not how I should be doing it >:).

Is this the best way to handle that? It does what I want, but I'm unsure if it may have performance issue or any other issues along the way as I begin to add more features. If it isn't, what would be the best alternative? Thanks in advance.

Upvotes: 0

Views: 468

Answers (1)

francis
francis

Reputation: 6349

Your question is not very clear and it doesn't really sound like you're looking for anything related to multithreading.

If your goal here is to add text incrementally to a TextField....

There are different tweener classes such as TweenMax or Tweener but you could do this just as easily with a Timer

Using a timer you could use something like this

private var myTextString:String = "The string you want to display 1 char at a time";

private function myButtonClickHandler(e:MouseEvent):void{
     if(!timer.running){ //so you don't click twice
         var timer:Timer = new Timer(1000, myTextString.length); //1000 is the delay (in ms), myString.length is the amout of times we want it to fire (once or every letter)
         timer.addEventListener(TimerEvent.TIMER, timerTick);
         timer.start();
     }
}

This assumes you have a text filed named myTextField

private function timerTick(e:TimerEvent):void{
    myTextField.text += myTextString.charAt(e.currentTarget.currentCount) //using the current count to add the next char to your text field
}

You're also going to want to reset this method using a timerComplete handler

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html#event:timerComplete

Upvotes: 2

Related Questions