有人可以帮助您在拖动对象时记录动作,当对象被删除时,记录事件将停止,录制的动作将通过“播放”按钮进行动画处理。
答案 0 :(得分:1)
设置一个存储记录信息的数组:
var recording:Array = [];
设置一个将信息添加到此数组的方法:
function record(target:MovieClip):void
{
recording.push(new Point(target.x, target.y));
}
开始拖动对象时执行此操作:
recording.length = 0;
addEventListener(Event.ENTER_FRAME, _record);
function _record(e:Event):void
{
record(yourObject);
}
停止拖动对象时执行此操作:
removeEventListener(Event.ENTER_FRAME, _record);
单击重播时执行此操作:
recording.reverse();
addEventListener(Event.ENTER_FRAME, _playRecording);
function _playRecording(e:Event):void
{
var step:Point = recording.pop();
yourObject.x = step.x;
yourObject.y = step.y;
if(recording.length < 1)
removeEventListener(Event.ENTER_FRAME, _playRecording);
}
您可以使用此方法将recording
数组转换为字符串:
function collapse(data:Array):String
{
var joined:Array = [];
for each(var point:Point in data)
{
joined.push(Math.round(point.x) + ":" + Math.round(point.y));
}
return joined.join("$");
}
最终结果如下:
trace(collapse(recording)); // 48:47$29:19$4:26$20:35$1:48$3:16$12:24$27:30$0:24$19:48
然后,您就可以使用它来创建recording
数组:
function expand(data:String):Array
{
var out:Array = [];
var base:Array = data.split("$");
for each(var fragment:String in base)
{
var coords:Array = fragment.split(":");
var point:Point = new Point(coords[0], coords[1]);
out.push(point);
}
return out;
}
其中的作用如下:
var previousData:String = "48:47$29:19$4:26$20:35$1:48$3:16$12:24$27:30$0:24$19:48";
var recording:Array = expand(previousData);
trace(recording); // (x=48, y=47),(x=29, y=19),(x=4, y=26),(x=20, y=35),(x=1, y=48),(x=3, y=16),(x=12, y=24),(x=27, y=30),(x=0, y=24),(x=19, y=48)