# Playback Movement

**URL:** <https://forum.kirupa.com/t/playback-movement/203260>\
**Category:** flash\
**Created:** [October 9, 2006, 4:09pm UTC](https://forum.kirupa.com/t/playback-movement/203260 "2006-10-09T16:09:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cki](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@cki](https://forum.kirupa.com/u/cki)\
**Post date:** [October 9, 2006, 4:09pm UTC](https://forum.kirupa.com/t/playback-movement/203260/1 "2006-10-09T16:09:08Z")

</div>

Hi,

The basic functionality works, dragging and dropping, but I’m having issues getting the movements to playback automatically should I create a pointer to the MC then apply an onLoad to it, the final goal is converting the AS to a Class:

```auto

var pointer:MovieClip=obj.CreateEmptyMovieClip("target_mc",depth);

```

```auto

var mainTimeline:Object = this;
var captureX:Array = new Array();
var captureY:Array = new Array();
var oldTime:Number = Math.round((getTimer()));
var mode:String;
function init() {
	captureX.length = 0;
	captureY.length = 0;
	oldtime;
}
//
init();
//
function captureMove(obj:MovieClip):Void {
	obj.onMouseDown = function() {
		if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
			setMode("record");
			this.startDrag();
			//trace("Object Dragging");
		}
		obj.onMouseUp = function() {
			setMode("playBack");
			this.stopDrag();
			//trace("Object Dropped");
		};
	};
}
//Records the movement of the object.
function record(mode:String):String {
	init();
	trace("Record Called");
	newTime = Math.round((getTimer()));
	if ((newTime-oldTime)>10) {
		captureX.push(this._x);
		captureY.push(this._y);
		oldTime = getTimer();
	}
	return mode;
}
//Should Playback the movements of the object.
function playBack(mode:String):String {
	trace("Playback Called");
	oldTime = getTimer();
	counter = 0;
	obj.onEnterFrame = function() {
		newTime = Math.round((getTimer()));
		if ((newTime-oldTime)>10) {
			this._x = captureX[counter];
			this._y = captureY[counter];
			counter = counter+1;
			if (counter>captureY.length) {
				counter = 0;
			}
			oldTime = getTimer();
		}
	};
	return mode;
}
function setMode(mode:String):Void {
	if (mode == "record") {
		record();
		trace("Mode Record");
	} else if (mode == "playBack") {
		playBack();
		trace("Mode Playback");
	}
}
captureMove(obj_mc);

```

The following code from a publication does work when applied to a MC via FLASH 5 syntax:

```auto

onClipEvent(load) {
captureX = new Array();
captureY = new Array();
oldTime = int(getTimer());

}

onClipEvent(mouseDown) {
if (this.hitTest(_root._xmouse,_root._ymouse,true)) {
this.startDrag();
mode = "record";
captureX.length = 0;
captureY.length = 0;
}
}

onClipEvent(mouseUp) {
stopDrag();
mode = "play";
oldTime = getTimer();
counter = 0;
}

onClipEvent(enterFrame) {

if (mode == "record") {
newTime = int(getTimer());
if ((newTime - oldTime) > 10) {
captureX.push(this._x);
captureY.push(this._y);
oldTime = getTimer();
}
}

if (mode == "play") {
newTime = int(getTimer());
if ((newTime - oldTime) > 10) {
this._x = captureX[counter];
this._y = captureY[counter];
counter = counter + 1;
if (counter > captureY.length) {
counter = 0;
}
oldTime = getTimer();
}
}
}

```

Any help is greatly appreciated.
