//放在第一帧调用
import flash.events.Event;
import flash.display.MovieClip;
stage.addEventListener(Event.ENTER_FRAME,onUpdate);
var bStop:Boolean = false;
//var saveFile:FileReference = new FileReference();
var str:String = new String("{");
function onUpdate(event:Event):void
{
if(!bStop)
{
str = str+"""+ currentFrame+"""+":{";
for(var j:int = 0;j<=this.numChildren - 2;j++)
{
var movieClip:MovieClip = this.getChildAt(j) as MovieClip;
str = str + """+movieClip.name+"":{"x":"+movieClip.x+","y":"+movieClip.y+","rotation":"+movieClip.rotation+"},";
}
var movieClip:MovieClip = this.getChildAt(this.numChildren - 1) as MovieClip;
str = str + """+movieClip.name+"":{"x":"+movieClip.x+","y":"+movieClip.y+","rotation":"+movieClip.rotation+"}},";
}
}
//放在最后一帧调用
stop();
bStop = true;
function replaceAt(char:String, value:String, beginIndex:int, endIndex:int):String
{
beginIndex = Math.max(beginIndex, 0);
endIndex = Math.min(endIndex, char.length);
var firstPart:String = char.substr(0, beginIndex);
var secondPart:String = char.substr(endIndex, char.length);
return (firstPart + value + secondPart);
}
str = replaceAt(str,"",str.length - 1,str.length);
str = str+"}"
trace(str);
var saveFile:FileReference = new FileReference();
saveFile.save(str,"mytest.txt");
//json文件格式如下
以上方法可以用作精灵的运动轨迹