I was wondering what was the best way to change the layering of objects in Flash? My project is made up of mostly small individual movie clips. I want to better organize my objects into layers so that one set of movieclips can be shown above another at a given time without any conflicts. Any advice on the best way to do this would be great.
EDIT: Getting errors with the following:
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
var backgroundLayer:Sprite = new Sprite;
backgroundLayer.name = "backgroundLayer";
var gameLayer:Sprite = new Sprite;
gameLayer.name = "gameLayer";
var menuLayer:Sprite = new Sprite;
menuLayer.name = "menuLayer";
public function Main()
{
addChild(backgroundLayer);
addChild(gameLayer);
addChild(menuLayer);
Errors are:
1120: Access of undefined property backgroundLayer.
1120: Access of undefined property gameLayer.
1120: Access of undefined property menuLayer.
Thanks.
Probably the easiest way to do this is to make a hierarchy of DisplayObjectContainer
s or its subclasses. (Sprite
, MovieClip
, etc.) Once these are added to the stage in the proper order, any children of these containers will be "within" the layer of the container.
To move an object between these layers in code, you just have to oldLayer.removeChild(thing); newLayer.addChild(thing);
.
Whether or not this is the "best" way to do this depends on what you are doing, but this is a way that I've done game object layering in the past.