Display List, Stacking Order glitch?
I just scripted some nice tweens for different navigation buttons, using addChildAt to fade in an image, a translucent gray box and two text fields (a header and a body) on top of these. I specify Z-positions 0,1,2,and 3 respectively for the objects.
The glitch is, I think, in the display list: the first button I click, its objects fade in, no problem.
But when I test the next button, there's no change. Its tween doesn't execute. The first displayed objects won't move out of the way, and the new children aren't added at position 0,1,2,3 in the z-order.
Is there somewhere I should execute a listener and a removeChildAt? a push method?
Any help would be appreciated.
It turns out removeChildAt was the answer to this. Although I still have questions, the resolution looked like this.
I had created movie clips showing fade-ins of an image, then a gray box and text upon the box (the gray box made the text easier to read atop the image, looked classy, etc.). I then right clicked on one of these movieclips in the library, selected linkage, and made a class out of them as follows: when the linkage dialog box popped up, I clicked Export for ActionScript. The dialog box names the class using the name of my object, but I can change this to whatever I want. I don't touch "base class." After I've named this little project specific mini-class, I press okay. (We'll call this mini-class "mainIn", for the movie that fades in when a user pushes the "main" button on the navigation bar.)
From the first frame of the timeline in the actions layer, I call an instance of mainIn, when a the "main" button is pushed. The code looks like this:
var newMainIn:MainIn=new MainIn();
trace("main page fades in");
This adds the movie clip and its delightful tweens and its timing to "0" on the display list, whenever the main button is clicked.
Notice I used MOUSE_UP as my mouse event. That's because I also call a function on MOUSE_DOWN, called onClick, which will remove any existing objects at "0" on the display list before MOUSE_UP adds the movieclip to the stage.
So that event listener looks like this:
onClick looks like this:
if ( numChildren > 0)
removeChildAt( 0 );
trace("prev. screen removed and now:");
onClick checks to see if there's a child at 0 and if so, removes it.
I've run into trouble with this method when a movie clip has another nested button or movie clip within it - onClick gets confused and leaves some objects on screen even as it plays the requested movie.
NOTE ALSO: that using this method, you may not see any objects the first time you test the movie. That I've found is due to the need to tweak your x and y positions for the movie clip instance within the function that calls your mini-class's instance (here, MainPageFadeIn).
Hope someone gets something out of this.