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.
They save an
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;
}
}
}
}
}