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

     

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

  • 相关阅读:
    Java中IO流的总结
    Java常用集合体系以及相互区别
    TreeMap集合特点、排序原理
    HashMap集合
    TreeSet集合
    redis 数据类型详解 以及 redis适用场景场合
    You need tcl 8.5 or newer in order to run the Redis test
    PHP 获取二维数组中某个key的集合
    Linux 定时任务
    phpmailer邮件类
  • 原文地址:https://www.cnblogs.com/HemJohn/p/4728686.html
Copyright © 2020-2023  润新知