-
Ronze
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!
-
Senior Member
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
- The right of the People to create Flash movies shall not be infringed. -
-
Ronze
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?
-
Senior Member
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.
- The right of the People to create Flash movies shall not be infringed. -
-
Ronze
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|