dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] mc.stage.addChild vs mc.addChild

Hybrid View

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    88

    resolved [RESOLVED] mc.stage.addChild vs mc.addChild

    I have the followings:

    _p:Player (which is a MC)
    a1:Animation1 (which is a MC)

    _p.addChild(a1); //doesn't display anything
    _p.stage.addChild(a1); //displays a1

    Why won't the MC display a child without using his stage?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    _p is probably moved off the visible area or otherwise set invisible (visible = false or alpha = 0). Or a1 is placed such that when it is relative to _p's coordinate system it is off the viewable area.

  3. #3
    Member
    Join Date
    Sep 2009
    Posts
    88
    trace(_p.visible, _p.x, _p.y, _a1.x, _a1.y, _a1.visible);
    true 100 250 100 250 true

    So it is visible and should be seen.

    I thought maybe it was because I made the var a1:Animation1 in a function so it didn't keep the var once function is done but then I 've put it in the class (changed name to _a1) properties so it should stay there.

    Also want to add that I'm addchilding to the MC from a 3rd party class.

    Is there some limitations on adding childs directly to a mc froma 3rd class or should it work normally?

  4. #4
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    What is _p a child of? The stage itself?

  5. #5
    Member
    Join Date
    Sep 2009
    Posts
    88
    Quote Originally Posted by Alluvian View Post
    What is _p a child of? The stage itself?
    It's from the document (main) class. I guess it means it's from stage?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    There is something I can't tell going on. I don't really fully understand your setup. Can you post full code, or at least all relevant excerpts? There should be no difference between adding A to B from one class vs another.

  7. #7
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    trace(_p.visible, _p.x, _p.y, _a1.x, _a1.y, _a1.visible);
    true 100 250 100 250 true

    Adding _a1 as a child of _p would put _a1 at x:200, y:500 globally, is that visible? I don't know the size of your stage.

  8. #8
    Member
    Join Date
    Sep 2009
    Posts
    88
    Quote Originally Posted by Alluvian View Post
    trace(_p.visible, _p.x, _p.y, _a1.x, _a1.y, _a1.visible);
    true 100 250 100 250 true

    Adding _a1 as a child of _p would put _a1 at x:200, y:500 globally, is that visible? I don't know the size of your stage.
    A quick try to _a1.y = 100 made it visible so you were right.

    I didn't guess that tracing .x .y of a mc is relative to his parent.

    Thanks.

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