Thursday, June 29, 2006

Flash: Using swapDepths()

So you want to change the depth of your pictures and text in Flash with ActionScript?

Check out this tutorial, Depths - How they work in Flash, at The first page you should already know if you been doing coding ActionScript professionally for some time. It is the second page that is the most interesting:

Major points of the second page:
  • Timeline Zone: Flash places static items on the timeline in depths -16,384 to -1.
  • Dynamic Zone: Dynamically placed movieclips are in 0 to 1,048,575 (and can only be removed from this range)
  • Reserved Zone: Dynamically placed movieclips can be in 1,048,576 to 2,130,690,04, (but can't be removed)
  • The exception to these zones is createEmptyMovieClip method. There is no limit for the depth when creating an empty movieclip.
  • The timeline refreshes when gotoAndPlay() is called. Timeline refreshes do not keep dynamically placed movieclips on the screen if they were placed there by a frame in the future of the timeline. Example: A movieclip is dynamically created (or swapDepths is called, placing the movieclip in the "Dynamic Zone") in frame 10. A refresh occurs in frame 5, when gotoAndPlay(5) is called. The dynamically created movieclip (from frame 10) dissappears.
  • If you use swapDepths to bring a movieclip which was placed on the timeline originally to a depth above 0 (not the Timeline Zone), then in a timeline refresh, that clip will not be removed in the clearing of the depths (the refresh) and a new instance of the same movieclip will be placed at its original depth, thus duplicating it and causing runtime errors that Flash Player will not flag.
So what is one to do? If you just swapping movieclips back and forth, like in this template for the Renaissance Pointe, then call swapDepths() with a negative value.

--Stephen M. James


Post a Comment

<< Home