zoukankan      html  css  js  c++  java
  • 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文件格式如下

     

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

  • 相关阅读:
    memcached全面剖析
    WiX安装选项注册程序集到GAC和VS的设计时环境
    WiX和DTF介绍
    WCF REST Starter Kit
    Windows 远程管理WinRM
    启用WCF NetTcpBinding的共享端口
    RESTful WCF
    ASP.NET可以在Windows Server 2008 R2 Server Core上运行
    asp.net mvc cms项目Oxite
    推荐一个非常不错的WCF通用代理类
  • 原文地址:https://www.cnblogs.com/HemJohn/p/4728686.html
Copyright © 2011-2022 走看看