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

Text shows up in new textbox even though not told to.

New Here ,
Aug 23, 2014 Aug 23, 2014

So this is my problem. I'm working on making a text based game to learn a bit more coding but even after looking around I cannot find a way to fix this.

The point of the code is to have a type writer effect, I do have a button to make it jump to the end of the timer and show all the text at once but because it does not seem to be part of the issue I have omitted it from below.

What happens with the code below is that when the button is pressed a blank text box will appear instead of displaying the new sting of text. If the button is pressed before the text has finished typing the text that appears in the next frame will be the text that didn't have time to display.

I have tested by having the 2nd frame just be T1.text = "NewTexthere" and it worked correctly but when the type writer effect is applied it no longer works.

----Frame 1----

stop()

T1.text = ""

var i=0;

var myString:String = "Text"

var mytimer:Timer = new Timer(10,myString.length);

mytimer.addEventListener(TimerEvent.TIMER, timerHandler);

mytimer.start();

function timerHandler(event:TimerEvent):void{

T1.appendText (myString.charAt(i));

i++;

}

Button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);

function fl_ClickToGoToNextFrame(event:MouseEvent):void

{

    nextFrame();

    mytimer.stop();

}

-----Frame 2----

T1.text = ""

var i2=0;

var myString2:String = "NewTextHere"

var mytimer2:Timer = new Timer(10,myString.length);

mytimer2.addEventListener(TimerEvent.TIMER, timerHandler);

mytimer2.start();

function timerHandler2(event:TimerEvent):void{

T1.appendText (myString.charAt(i2));

i++;

}

---------

TOPICS
ActionScript
289
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

correct answers 1 Correct answer

LEGEND , Aug 24, 2014 Aug 24, 2014

WHy do you use the string rfrom frame 1 when you define a new string in frame 2?  Why do you increment i when you are using i2?  Between the two of those you might find the problem.

var i2=0;

var myString2:String = "NewTextHere";

function timerHandler2(event:TimerEvent):void{

    T1.appendText (myString.charAt(i2));

   i++;

}

Translate
LEGEND ,
Aug 24, 2014 Aug 24, 2014

WHy do you use the string rfrom frame 1 when you define a new string in frame 2?  Why do you increment i when you are using i2?  Between the two of those you might find the problem.

var i2=0;

var myString2:String = "NewTextHere";

function timerHandler2(event:TimerEvent):void{

    T1.appendText (myString.charAt(i2));

   i++;

}

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
New Here ,
Aug 24, 2014 Aug 24, 2014

Thank you I KNEW it had to be something like a misplaced number. After fixing those I still got the error but I noticed that in

mytimer2.addEventListener(TimerEvent.TIMER, timerHandler);

I put (timerHandler) as oppose to (timerHandler2) which made it use the old timer. Likewise for var mytimer2:Timer = new Timer(10,myString.length); in which the old string was used.

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 24, 2014 Aug 24, 2014
LATEST

You're welcome

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