Question

I have a Grid component and it's verticalScrollPolicy is set to "auto". And every time when verticalScrollBar appears or disappears, I want to handle this event.

I tried to listen to the RESIZE event:

    private function onGridResize(event:Event):void
    {
       if (_grid.verticalScrollBar && _grid.verticalScrollBar.visible)
       {
           trace("scroll on");
       }
       else
       {
           trace("scroll off");
       }
    }

but it does not work: it seems to me, that RESIZE event actually dispatches before grid visual update and scrollbar appear/disappear. I tried to listen ChildExistenceChangedEvent.CHILD_ADD and ChildExistenceChangedEvent.CHILD_REMOVE events as well, but it doesn't work for me too.

Maybe I just don't see some obvious solution. Thanks in advance for any help or advise.

Was it helpful?

Solution

You do not specify which grid. (Spark, MX, or one of ours (http://www.flexicious.com/Home/Ultimate) )

One thing you could do is throw a validateNow prior to checking:

private function onGridResize(event:Event):void
    {
       _grid.validateNow(); //add this.

       if (_grid.verticalScrollBar && _grid.verticalScrollBar.visible)
       {
           trace("scroll on");
       }
       else
       {
           trace("scroll off");
       }
    }

The other thing you could also do, is use a timer or call later.

private function onGridResize(event:Event):void
    {
       callLater(checkForScrollBar); //check for scrollbar would have the code above.
    }

OTHER TIPS

Perhaps you can listen for the "show" event of the ScrollBar itself. Something along the lines of this should work:

_grid.verticalScrollBar.addEventListener(ComponentEvent.SHOW, onGridResize);

I haven't tested this, but I'm pretty sure it should work. (Of course, you may want to rename onGridResize to something more suitable like onVerticalScrollShow.)

By the way, you don't have to check that the ScrollBar exists; in pure AS3 at least, they are instantiated along with the DataGrid and exist regardless of their ScrollPolicy value.

The reason the resize event appears to fire right away is because it is dispatched as soon as its dimensions change. I'm assuming that in your application, the user drags to manually adjust the grid's size, and thus the events fires as soon as any adjustment is made.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top