Return to Starling Playback Library

Copying of GAFMovieClip object

Questions related to Starling playback library should be asked here.

Copying of GAFMovieClip object

Postby Андрейка Байдин » February 11th, 2016, 10:23 pm

Suggest that i want to make a copy of existing GAFMovieClip object. What i'm doing is:
Code: Select all
function myFunction(source:GAFMovieClip):void
{
  var theCopy:GAFMovieClip = source.copy();
  trace(source.currentFrame);    // 8
  trace(theCopy.currentFrame); //1
}

ok, can handle it:
Code: Select all
function setFrameRecursive(source:GAFMovieClip, target:GAFMovieClip)
{
  target.gotoAndStop(source.currentFrame);
  for (var i:int; i < sorce.numChildren; ++i)
    setFrameRecursive(source.getChildAt(i), target.getChildAt(i));
}

Actually no. Because numChildren and order of children aren't the same for source and it's copy. Maybe i can restore it after copying. I'm trying the following way:
Code: Select all
        function setChildrenPositionsFromCopy(from:GAFMovieClip, to:GAFMovieClip):void
        {
            to.gotoAndStop(from.currentFrame);
            for (var i:int = 0, len:int = from.numChildren; i < len; ++i)
            {
                var fromChild:DisplayObject = from.getChildAt(i);
                to.addChildAt(to.getChildByName(fromChild.name), i);

                var fromChildMC:GAFMovieClip = fromChild as GAFMovieClip;
                if (fromChildMC != null) setChildrenPositionsFromCopy(fromChildMC, to.getChildAt(i) as GAFMovieClip);
            }
            for (var i:int = to.numChildren - 1, l:int = from.numChildren; i >= l; --i)
            {
                var isDisposed:Boolean = from.getChildByName(to.getChildAt(i).name) == null;
                to.removeChildAt(i, isDisposed);
            }
        }

But this doesn't work either, because not all elements in the tree have the non-null name property. Maybe you could help me to find the way to iterate over the children of 2 copies of GAFMovieClip?
User avatar
Андрейка Байдин
 
Posts: 1
Joined: February 11th, 2016, 9:47 pm

Re: Copying of GAFMovieClip object

Postby vadym.mitin » February 15th, 2016, 9:35 am

Hi,

There is no way to make exact copy of the GAFMovieClip like you want to do. It is impossible to do with the regular flash MovieClip and for the same reason it is impossible to do with GAFMovieClip. A little bit more about it in this topic viewtopic.php?f=4&t=528

You can iterate over the children and make sure that they are the same in original instance and in the copy only in the following conditions:
    - all the children in the designed animation appears in the first frame and exist in all frames;
    - z-index of the all children in the designed animation remains the same in all frames;
    - there are no dynamically added or removed children in runtime;
    - the rules described above are applied to all nested movieclips.

If any of the rules above doesn't take place - you'll get unexpected result.
User avatar
vadym.mitin
 
Posts: 254
Joined: December 4th, 2013, 8:00 am

Return to Starling Playback Library

Who is online

Users browsing this forum: No registered users and 1 guest