# How to change the code to work automatically instead of using Play button?

**URL:** <https://forum.kirupa.com/t/how-to-change-the-code-to-work-automatically-instead-of-using-play-button/324657>\
**Category:** flash\
**Created:** [September 1, 2011, 7:44pm UTC](https://forum.kirupa.com/t/how-to-change-the-code-to-work-automatically-instead-of-using-play-button/324657 "2011-09-01T19:44:21Z")\
**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:** [September 1, 2011, 7:44pm UTC](https://forum.kirupa.com/t/how-to-change-the-code-to-work-automatically-instead-of-using-play-button/324657/1 "2011-09-01T19:44:21Z")

</div>

Hi,

The following code draws a square on using Play Button. But I want it to be started drawing automatically without using the Play Button. I got the example code from searching the google.

```auto
import com.greensock.*;
import flash.events.MouseEvent;

//create line
var line:Shape = new Shape();
addChild(line);

//position mc at first point
mc.x = p1.x;
mc.y = p1.y;

var tl:TimelineMax = new TimelineMax({paused:true,onUpdate:drawLine});

tl.appendMultiple([
  TweenLite.to(mc, 1, {x:p2.x, y:p2.y}),
  TweenLite.to(mc, 1, {x:p3.x, y:p3.y}),
  TweenLite.to(mc, 1, {x:p4.x, y:p4.y}),
  TweenLite.to(mc, 1, {x:p1.x, y:p1.y})
  ], 0, TweenAlign.SEQUENCE);

function drawLine():void
{
    line.graphics.lineTo(mc.x, mc.y);
}

play_btn.addEventListener(MouseEvent.CLICK, playTl);

function playTl(e:MouseEvent):void
{
    //kill existing line
    line.graphics.clear();
    
    //start new line at first point
    line.graphics.lineStyle(2, 0xFFFF00, .5);
    line.graphics.moveTo(p1.x, p1.y);
    
    tl.restart();
}

```

Please do help.
