Copy link to clipboard
Copied
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++;
}
---------
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++;
}
Copy link to clipboard
Copied
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++;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now