# Code for "Restart\_btn" to play again

**URL:** <https://forum.kirupa.com/t/code-for-restart-btn-to-play-again/325641>\
**Category:** Uncategorized\
**Created:** [October 27, 2011, 10:05am UTC](https://forum.kirupa.com/t/code-for-restart-btn-to-play-again/325641 "2011-10-27T10:05:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![learner\_7n](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@learner\_7n](https://forum.kirupa.com/u/learner_7n)\
**Post date:** [October 27, 2011, 10:05am UTC](https://forum.kirupa.com/t/code-for-restart-btn-to-play-again/325641/1 "2011-10-27T10:05:50Z")

</div>

Hi,

The following code is okay (Without “Restart\_btn”. But I would like to add a button to play the animation again. How to do that? Please guide me.  
The Code in Blue works fine. Just required code for the red one.  
[COLOR=#0000ff]var str:String = “Demonstration text is used here.”;[/COLOR]  
[COLOR=#0000ff]var myTimer:Timer = new Timer(1, str.length);  
myTimer.addEventListener(“timer”, writeIt);  
myTimer.start();  
var count:Number = 0;[/COLOR]  
[COLOR=#0000ff]function writeIt(event:TimerEvent):void {  
theText.text = str.substring(0,count);  
count++;  
if (count \> str.length) {  
myTimer.removeEventListener(“timer”,writeIt);  
}  
}  
[/COLOR]  
[COLOR=#ff0000]Restart\_btn.addEventListener(MouseEvent.CLICK, clickRestart);[/COLOR]  
[COLOR=#ff0000]function clickRestart(event:MouseEvent) { gotoAndPlay(1); }

[/COLOR]Thanks.
