• Flash as3.0 保存MovieClip运动轨迹到json文件


    //放在第一帧调用

    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文件格式如下

     

    以上方法可以用作精灵的运动轨迹

  • 相关阅读:
    4.6--4.9
    4.表达式和运算符
    3.9--3.10
    3.8
    泛型(Generic)
    容器
    String,StringBuffer
    数组
    异常,自定义异常,异常重写
    多态,抽象类和抽象方法,接口
  • 原文地址:https://www.cnblogs.com/HemJohn/p/4728686.html
Copyright © 2020-2023  润新知