Flash AS3:保存/加载 MovieClip 的所有子级的位置 [英] Flash AS3: saving/loading the positions of all the children of a MovieClip

查看:19
本文介绍了Flash AS3:保存/加载 MovieClip 的所有子级的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何保存和加载 MovieClip 的所有子项的 X 和 Y 位置.

I would like to know how to save and load the X and Y position of all the children of a MovieClip.

我有一个带有保存和加载按钮的项目.

I have a project with a save and load button.

他们保存并加载 MovieClip 子元素的 X 和 Y 位置.

They save and load the X and Y position of the MovieClip's child.

save.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler3);

function fl_MouseClickHandler3(event:MouseEvent):void
{

var mySo:SharedObject = SharedObject.getLocal("SaveData");

mySo.data.my_x = mc2.x;
mySo.data.my_y = mc2.y;
mySo.flush();


}

loader.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{

var mySo:SharedObject = SharedObject.getLocal("SaveData");


mc2.x = mySo.data.my_x;
mc2.y = mySo.data.my_y;

}

然而,这只会保存和加载最后点击的 MovieClip 子级.如何从仅保存和加载上次单击的 MovieClip 子项中更改它,保存和加载所有 MovieClip 子级?

This however only saves and loads the last clicked MovieClip child. How can I change it from only saving and loading the last clicked MovieClip child, to saving and loading all the MovieClip children?

推荐答案

这将始终保存mc2"位置,您需要在影片剪辑的 numchildrens 上运行一个循环并将它们的位置放在一个数组中,然后访问它们以同样的方式.这是一个代码示例

That will always save "mc2" positions, you will need to run a loop on numchildrens of the movieclip and put their positions in an array, and then access them in the same way. Here is a code example

import flash.display.MovieClip;

var mySo:SharedObject = SharedObject.getLocal("SaveData");
save.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler3);
loader.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler3(event:MouseEvent):void
{
    var clippositions:Array = new Array();
    var child:MovieClip;
    for(var i:uint=0; i<this.numChildren; i++)
    {
        if( this.getChildAt(i) is MovieClip )
        {
            child = this.getChildAt(i) as MovieClip;
            if(child)
            {
                clippositions.push( { clipname:child.name, my_x:child.x,my_y:child.y } );
            }
        }
    }
    mySo.data.clippositions = clippositions
    mySo.flush();
}

function fl_MouseClickHandler_2(event:MouseEvent):void
{
    var clippositions:Array = mySo.data.clippositions;
    if( clippositions != null )
    {
        var child:MovieClip;
        for(var i:uint=0; i<clippositions.length; i++)
        {
            if( this.getChildByName( clippositions[i].clipname ) is MovieClip )
            {
                child = this.getChildByName( clippositions[i].clipname ) as MovieClip;
                if(child)
                {
                    child.x = clippositions[i].my_x;
                    child.y = clippositions[i].my_y;
                }
            }
        }
   }
}

这篇关于Flash AS3:保存/加载 MovieClip 的所有子级的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆