简体   繁体   中英

AS3: How to find the parent of a deep-nested Sprite from the Stage?

I'll give a complete explanation of what I'm trying to do.

I have a video player as a separate SWF. In this video player I have a VideoContainer class extending Sprite, which contains the video and a control bar with specific video buttons.

This SWF is loaded in another main SWF, which has a menu that is on top of everything else. When I click "Fullscreen" in the video SWF, everything goes smoothly, except the menu remains on top of the VideoContainer object.

I need a way to change the display order of the loaded SWF, to put it on top of everything else on Fullscreen and change it back when Fullscreen goes off. All this needs to be made inside the video player. Also, the configuration of the children can change (the video player can be loaded in different places in the main SWF), so I can't use a certain unchanging path.

I would like to do something like stage.getUpperMostParentOf(VideoContainer) . Any ideas? Thanks.

Can you just add the loaded swf again? From your main swf:

addChild( menu ); // -- the menu sprite
addChild( videoSWF ); // -- the loaded swf containing the video player

Another approach to finding the top most parent that isn't the stage would be to "climb" up the display tree with a while loop.

var container:DisplayObjectContainer = videoContainer.parent;
while( container.parent != null && containert.parent != stage )
{
     container = container.parent
}

trace( 'uppermost parent: ' + parent );

There are probably multiple ways to accomplish what you want, but without seeing your actual code, it's difficult to know exactly how to solve this.

I've done this and is quite straight-forward... from the videoplayer:

var oldParent:DisplayObjectContainer;
function goFullscreen() {
    oldParent=parent;
    stage.addChild(this);
    stage.displayState=StageDisplayState.FULL_SCREEN;
    stage.addEventListener(Event.RESIZE, resize);
}

function resize(e) {
    if(stage.displayState!=StageDisplayState.FULL_SCREEN) {
        stage.removeEventListener(Event.RESIZE, resize);
        oldParent.addChild(this);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM