Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Strange duplicating of objects when re-parenting clips using addChild

Explorer ,
Mar 28, 2016 Mar 28, 2016

I'm making an accordion folder where I have 4 tabs that tween up and down in groups when one of the tabs is clicked.  The tabs were created in Flash and exist as named instances on the stage. If you click on the tab1 (top tab), the bottom 3 tabs tween down to reveal the contents under tab1. I have a listener on each tab with a corresponding function to go to a key frame that has the tween and some UI modifications.

To make the tabs open as a group I have an empty container clip that I use to add the tabs as children.

myContainer.addChild(Tab2);

myContainer.addChild(Tab3);

myContainer.addChild(Tab4);

I then tween the container clip to make them all move down. 

When another tab is clicked, I go to another key frame that has the closing  tween and some UI modifications.

At the end of the tween I re-parent the tabs to the original parent by adding them as children to "this' i.e. their original location.

this.addChild(Tab2);

this.addChild(Tab3);

this.addChild(Tab4);

After that there is a jump to the new  opener key frame and the cycle repeats.

This works fine when tabs are clicked once each.  But if you click a tab again after opening other tabs, there are duplicate instances of the tabs.  I can't figure out why.  I assumed that using addChild with different clips would simply swap the parent and not create a new instance. It also occurred to me that maybe I needed to refresh the display after the tween.  I don't know how to do that. updateAfterEvent doesn't seem to work with Tweens.  Then again I believe he duplicates are actual instances because they respond to mouse actions.

So how can I re-parent clips so that they are not duplicated but can be grouped and released to make new groups?

TOPICS
ActionScript
259
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2016 Mar 28, 2016
LATEST

reparented objects aren't duplicated. you have something else causing the problem you're seeing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines