Using a custom label function on a FileSystemTree control in Adobe AIR

by Peter deHaan on December 14, 2008 · 0 comments

in FileSystemTree

The following example shows how you can create a custom label function on an Adobe AIR FileSystemTree control by setting the labelFunction property to a custom function.

Full code after the jump.

The following example creates a custom label function which appends a string to hidden files and folders:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/14/using-a-custom-label-function-on-a-filesystemtree-control-in-adobe-air/ -->
<mx:WindowedApplication name="FileSystemTree_labelFunction_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle">
 
    <mx:Script>
        <![CDATA[
            private function tree_labelFunc(item:File):String {
                var value:String = item.name;
                if (item.isHidden) {
                    value += " (hidden)";
                }
                return value;
            }
        ]]>
    </mx:Script>
 
    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="showHidden:"
                labelPlacement="left" />
    </mx:ApplicationControlBar>
 
    <mx:FileSystemTree id="tree"
            labelFunction="tree_labelFunc"
            showHidden="{checkBox.selected}"
            width="100%"
            height="100%" />
 
</mx:WindowedApplication>

The following example creates a custom label function which displays the document’s file size (in kilobytes) next to the file name:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/14/using-a-custom-label-function-on-a-filesystemtree-control-in-adobe-air/ -->
<mx:WindowedApplication name="FileSystemTree_labelFunction_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle">
 
    <mx:Script>
        <![CDATA[
            private function tree_labelFunc(item:File):String {
                var value:String = item.name;
                if (!item.isDirectory) {
                    value += " (" + numFormatter.format(item.size/1024) + " KB)";
                }
                return value;
            }
        ]]>
    </mx:Script>
 
    <mx:NumberFormatter id="numFormatter" precision="1" useThousandsSeparator="true" />
 
    <mx:FileSystemTree id="tree"
            labelFunction="tree_labelFunc"
            width="100%"
            height="100%" />
 
</mx:WindowedApplication>

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: