Skip to main content
Inspiring
August 16, 2013
Question

zindex and play()

  • August 16, 2013
  • 2 replies
  • 2281 views

I've looked on Google for a solution for this and was unable to find anything, or I'm just not using the correct terminology, so any help would be appreciated.

I've noticed that when using a depth altering method such as swapChildren along with some sort of play() method, that the swapped mcs are copied on the stage and their timeline begins playing. the swapped mcs are both mcs inside an mc.

// swapChildren() is executed first, then play()

// Any other time play() is used the bug does not show up

private function charDirection(currentKey:uint):void

{

    if (currentKey != _previousKey)

    {

        _previousKey = currentKey;

        this.scaleX *= -1;

        trace(this.numChildren);

        this.swapChildren(mainChar_shield, mainChar_spear);

    }

}

private function walkingLoop():void

{

    if (currentLabel != "Walking")

    {

        gotoAndPlay("Walking");

    } else {

        play();

    }

}

mainChar_shield is an mc inside mainChar mc.

I've also been told that you shouldn't change the zindex of an mc that's been instantiated by the timeline. So I'm wondering if there's another way to do this or some hack around it.

Thanks


This topic has been closed for replies.

2 replies

Inspiring
August 17, 2013

The issue is not swapping but the fact that when you use this.gotoAndStop(1); in onKeyboardUp - new instances are created. See how number of children is output here:

private function onKeyboardUp(event:KeyboardEvent):void

{

          if (event.keyCode == Keyboard.A || event.keyCode == Keyboard.D)

          {

                    _vx = 0;

 

                    this.gotoAndStop(1);

                    trace("onKeyboardUp", this.numChildren);

          }

 

          if (event.keyCode == Keyboard.S)

                    action("DefenseStanceUp", 40);

}

kglad
Community Expert
Community Expert
August 17, 2013

the issue is caused by swapChildren and a frame loop.  you can confirm it is, at least, a key part the issue in the op's project by commenting out the swapChildren() method.

check the attached fla. which shows the only key parts needed to display the issue are a frame loop and swapChildren.

Inspiring
August 17, 2013

Yeah, you are right - just realized it.

kglad
Community Expert
Community Expert
August 16, 2013

what "bug" do you think you seeing?

and there's nothing taboo about changing the index of an object added in the authoring environment any more than it's taboo to change the zindex of an object added using actionscript.

bobocheezAuthor
Inspiring
August 16, 2013

So when play() is executed after swapChildren() the 2 swapped mcs are duplicated. The original mcs are sent to the correct depth, but the new mcs are in the default zindex and their timeline begins playing.

Every time the trace() method above runs, it will show 12, 14, 16, n+2, ...

So here is the original

http://imageshack.us/a/img41/4360/2iq9.png

And after the direction is changed. Both of the new shield and spear are looping through their timeline

http://imageshack.us/a/img839/249/zayk.png

kglad
Community Expert
Community Expert
August 16, 2013

i'm not sure what you're trying to describe.

are you saying there's a stop() on the timeline of one (or more of your movieclips) and that stop() is ignored after using swapChildren?

are you saying there are more children (because of some kind of duplication) after using swapChildren compared with before using swapChildren?