# Lots of tutorials on the web use timeline

**URL:** <https://forum.kirupa.com/t/lots-of-tutorials-on-the-web-use-timeline/258065>\
**Category:** flash\
**Created:** [April 20, 2008, 2:40pm UTC](https://forum.kirupa.com/t/lots-of-tutorials-on-the-web-use-timeline/258065 "2008-04-20T14:40:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeechyBoy](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@BeechyBoy](https://forum.kirupa.com/u/BeechyBoy)\
**Post date:** [April 20, 2008, 2:40pm UTC](https://forum.kirupa.com/t/lots-of-tutorials-on-the-web-use-timeline/258065/1 "2008-04-20T14:40:53Z")

</div>

Lots of tutorials on the web use timeline based ActionScripting, but I want to turn lots of AS3 examples into Classes (packages) because this seems best practice if you wish to use the code over and over again.  
Rather than stab in the dark at the script and find myself in a maze of compile errors, I wondered if anyone would be able to post some rules and best practices on converting timeline to package code.

For example, how do I convert the AS below to run as a stand alone class?

```auto

var myTimer:Timer = new Timer(500);
myTimer.addEventListener("timer", timedFunction);

// Function will be called every 500 milliseconds
function timedFunction(eventArgs:TimerEvent) {
	trace(myTimer.currentCount);
	if (myTimer.currentCount==4) {
		woodblock.play();
		Reset();
		reply_txt.text = "Go Again?";
	}
}

function Reset() {

	var activateButton:resetButton = new resetButton();

	activateButton.x = 68;
	activateButton.y = 260;
	activateButton.addEventListener(MouseEvent.MOUSE_DOWN, resetShapes);
	//sets index depth for button to appear
	this.addChildAt(activateButton, 0);
}

var soundReq:URLRequest = new URLRequest("woodblock.mp3");
var woodblock:Sound = new Sound();
woodblock.load(soundReq);

var startX:Number;
var startY:Number;
var counter:Number = 0;

function shapesListening():void {
square_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
square_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
flower_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
flower_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
triangle_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
triangle_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
pentagon_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
pentagon_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}
shapesListening();

function pickUp(event:MouseEvent):void {
	event.target.startDrag(true);
	reply_txt.text = "";
	event.target.parent.addChild(event.target);
	startX = event.target.x;
	startY = event.target.y;
}
function dropIt(event:MouseEvent):void {
	event.target.stopDrag();
	var myTargetName:String = "target" + event.target.name;
	var myTarget:DisplayObject = getChildByName(myTargetName);
	if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget) {
		reply_txt.text = "Good Job!";
		// turns off dragging once has correct target name matched
		event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
		event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
		event.target.buttonMode = false;
		event.target.x = myTarget.x;
		event.target.y = myTarget.y;
		counter++;
		woodblock.play();
	} else {
		reply_txt.text = "Try Again!";
		event.target.x = startX;
		event.target.y = startY;
	}
	if (counter == 4) {
		// Start the timer
		myTimer.start();
		reply_txt.text = "Congrats, you're finished!";
		resetButton;
	}
}
function resetShapes(event:MouseEvent):void {
	square_mc.x = 61;
	square_mc.y = 61;
	flower_mc.x = 161;
	flower_mc.y = 81;
	triangle_mc.x = 60;
	triangle_mc.y = 160;
	pentagon_mc.x = 161;
	pentagon_mc.y = 181;
	shapesListening();
	myTimer.stop();
	myTimer.reset();
	counter = 0;
	this.removeChildAt(0);
	reply_txt.text = "";
}
square_mc.buttonMode = true;
flower_mc.buttonMode = true;
triangle_mc.buttonMode = true;
pentagon_mc.buttonMode = true;

```
