Skip to content
Dec 13 /

Programmatically scrolling to a selected node in the FileSystemTree control in Adobe AIR

The following example shows how you can automatically scroll to a node in an Adobe AIR FileSystemTree control by using the openSubdirectory(), findIndex(), and scrollToIndex() methods.

Full code after the jump.

Download FileSystemTree_scrollToIndex_test.zip

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/13/programmatically-scrolling-to-a-selected-node-in-the-filesystemtree-control-in-adobe-air/ -->
<mx:WindowedApplication name="FileSystemTree_scrollToIndex_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle">
 
    <mx:Script>
        <![CDATA[
            private function btn_click(evt:Event):void {
                var f:File = File.desktopDirectory;
                tree.openSubdirectory(f.nativePath);
                tree.validateNow();
                var idx:int = tree.findIndex(f.nativePath);
                tree.scrollToIndex(idx);
            }
        ]]>
    </mx:Script>
 
    <mx:ApplicationControlBar dock="true">
        <mx:Button id="btn"
                label="Open desktop directory"
                click="btn_click(event);" />
    </mx:ApplicationControlBar>
 
    <mx:FileSystemTree id="tree"
            width="100%"
            height="100%" />
 
</mx:WindowedApplication>

One Comment

leave a comment
  1. Pebble / Jan 26 2009

    Thanks! just what I was looking for!

Leave a Comment

Spam Protection by WP-SpamFree