tags:

views:

716

answers:

2

Is there a built in way to determine if a component is fully visible in a Flex application (i.e. not offscreen one way or the other). If not how would I go about figurin it out?

I want to show or hide additional 'next' and 'previous' buttons if my primary 'next' and 'previous' buttons are off screen.

What event would be best to listen to to 'recalculate' ? stage.resize?

thanks!

A: 

Could you give the specifics of the visible item and the container(s) it's in? Is it a matter of having to scroll some container to get to the buttons? Or is it a matter of someone has dragged a child window of a flexlib:MDICanvas partially off screen?

I think it's going to come down to if the x,y position of the component is beyond the width and height of its container, (and so on up through the parent containers until you reach your top level Application.)

Jim Carroll
+1  A: 

here is a method for calculating if the component is within the bounds of the stage, it will not however tell you if the component is being hidden by another component, or if the component is being hidden because it is outside the bounds of another container.

public function isComponentWithinStage(c:UIComponent):Boolean {
    var tl:Point = c.localToGlobal(new Point(0, 0));
    var br:Point = c.localToGlobal(new Point(c.width, c.height));

    //are we off the left or top of stage?
    if ( tl.x < 0 || tl.y < 0 ) {
     return false;
    }

    var stage:Stage = Application.application.stage;

    //off the right or bottom of stage?
    if ( br.x > stage.width || br.y > stage.height ) {
     return false;
    }

    return true;
}
maclema