-
AS3 depths problem
Hey everyone
I'm doing a fairly simple thing...
I have a MainClass, where I first make a background and add it to the stage.
Then I make a textfield and add it to the stage
But what really confuses me is, that the background gets an index of 2, and the textfield gets an index of 0???
that means that even though I added the textfield after the background it still display underneath the background. And when I try to setChildIndex(textfield, 1), it gives me the error message:
Error #2006: The supplied index is out of bounds
I simply don't get it!
-
Have you added the objects to different layers? Also you cannot select any depth but only the one following in the row.
var a:Square = new Square();
stage.addChild (a);
var b:Circle = new Circle();
addChild (b);
trace(getChildAt(0));//circle
trace(stage.getChildAt(0));//timeline
trace(stage.getChildAt(1));//square
-
Well, I add them like this, right next to eachother in the MainClass:
Code:
var background:Background = new BackGround(); // selfmade class
addChild(background);
var textfield:TextField = new TextField();
textfield.htmlText = "<b>Hello</b><br />This is a text";
addChild(textfield);
I actually made it work, when I loaded external text into it, instead of hardcoding the text like above. So that really confuses me, after I haven't changed any depth-properties.
But what does that error message mean? That there's no property in the specified index?
-
The depth is added consecutively. If you add an object it has a depth of 0. The next one will have 1. If you now want to add an object at the depth of 3 you will get an error, because there is no object at 2.
-
ok... just couldn't understand wy the first object was added at 1, and the next at 0... but it doesn't do it anymore.... hmmm.... but i works :-D