A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS3 depths problem

  1. #1
    Ronze Ronze's Avatar
    Join Date
    Oct 2002
    Location
    Copenhagen, Denmark
    Posts
    185

    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!
    --- Ronze ---

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  3. #3
    Ronze Ronze's Avatar
    Join Date
    Oct 2002
    Location
    Copenhagen, Denmark
    Posts
    185
    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?
    --- Ronze ---

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  5. #5
    Ronze Ronze's Avatar
    Join Date
    Oct 2002
    Location
    Copenhagen, Denmark
    Posts
    185
    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
    --- Ronze ---

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center