Flex 4 tree component - how to populate using an array?

It's unclear how to populate a tree control using an array as the dataprovider like you could in Flex 3.
Here is a Flex 3 example. Even when I replace the mx:Object tags with fx:Object tags things don't work ... there seems to be no mx:children tag ...
http://blog.flexexamples.com/2007/12/03/using-an-array-as-a-data-provider-in-a-flex-tree-c ontrol/
Please advise.

This should do it:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">
    <fx:Script>
        <![CDATA[
            private function tree_labelFunc(item:Object):String {
                var suffix:String = "";
                if (tree.dataDescriptor.hasChildren(item)) {
                    suffix = " (" + item.children.length + ")";
                return item.name.toUpperCase() + suffix;
        ]]>
    </fx:Script>
    <fx:Declarations>
        <fx:Array id="arr">
            <fx:Object name="One">
                <fx:children>
                    <fx:Array>
                        <fx:Object name="Two" />
                        <fx:Object name="Three" />
                        <fx:Object name="Four">
                            <fx:children>
                                <fx:Array>
                                    <fx:Object name="Five" />
                                    <fx:Object name="Six" />
                                </fx:Array>
                            </fx:children>
                        </fx:Object>
                        <fx:Object name="Seven">
                            <fx:children>
                                <fx:Array>
                                    <fx:Object name="Eight" />
                                </fx:Array>
                            </fx:children>
                        </fx:Object>
                        <fx:Object name="Nine" />
                    </fx:Array>
                </fx:children>
            </fx:Object>
        </fx:Array>
    </fx:Declarations>
    <mx:Tree id="tree"
            dataProvider="{arr}"
            labelFunction="tree_labelFunc"
            width="200"
            horizontalCenter="0"
            verticalCenter="0" />
</s:Application>
Peter
Update: I also posted the updated Spark example at http://blog.flexexamples.com/2007/12/03/using-an-array-as-a-data-provider-in-a-flex-tree-c ontrol/.

Similar Messages

  • How can I use my array in another method.... Or better yet, what's wrong?

    I guess I'll show you what I am trying to do rather and then explain it
    public class arraycalc
    int[] dog;
    public void arraycalc()
    dog = new int[2];
    public void setSize(int size)
    dog[1] = size;
    public int getSize()
    return dog[1];
    This gives me a null pointer exception...
    How can I use my array from other methods?

    You have to make the array static. :)
    Although I must admit, this is rather bad usage. What you want to do is use an object constructor to make this class an object type, and then create the array in your main class using this type, and then call the methods from this class to modify your array. Creating the array inside the other method leads to a whole bunch of other stuff that's ... well, bad. :)
    Another thing: Because you're creating your array inside this class and you want to call your array from another class, you need to make the array static; to make it static, you must make your methods static. And according to my most ingenious computer science teacher, STATIC METHODS SUCK. :D
    So, if you want to stick with your layout, it would look like:
    public class arraycalc
         static int[] dog;
         public static void arraycalc()
              dog = new int[2];
         public static void setSize(int size)
              dog[1] = size;
         public static int getSize()
              return dog[1];
    }But I must warn you, that is absolutely horrible code, and you shouldn't use it. In fact, I don't even know why I posted it.
    You should definitely read up on OOP, as this problem would be better solved by creating a new object type.

  • [F8] Tree Component: How can I hide/remove the scrollbar and border?

    I'm using the Tree Component in my Flash 8 Pro - Project. I'm
    trying to customize the look of the Tree component in two ways:
    1. Is there any way to remove the scrollbar from the Tree
    Component?
    2. Can I also remove the Border from the Tree Component?
    I checked the Component Inspector and couldn't find any
    options for the scrollbar nor the border.
    Does anyone know how to do this or could you point me in the
    right direction?
    Thanks

    You can use the Status-4-Evar extension to replace some functionality that was lost withthe removal of the Status bar in Firefox 4.
    Open the Customize window via "View > Toolbars > Customize" or via "Firefox > Options > Toolbar Layout" after you have installed the Status-4-Evar extension and drag the items (Status Text, Progress Meter, Download Status) upon the Add-ons Bar (View > Toolbars > [X] Add-on Bar)
    * Status-4-Evar: https://addons.mozilla.org/firefox/addon/235283/

  • How do I use an array variable in the assignment target?

    Hi,
    I am creating a BPEL process in which I have to use an array variable. The array variable needs to be initialized based on some condition.
    The issue is I cannot find a way to set the value of the array variable. There are ways to GET the value of an array variable indexing into it.
    But how do I set the value by using the Array variable in the <to> tag?
    Any help is appreciated. I am using BPEL 10.1.2.0.2.
    Thanks.

    You can declare a variable of type integer which will server as your index. Figure out based on some condition in your process which index of array to update. Assign to your integer variable you created.
    And have Assign copy operation like this -
    <copy>
    <from variable="Var_Output_FetchDueDate"
    part="OutputParameters"
    query="/ns18:OutputParameters/ns18:DUEDATE"/>
    <to variable="outputVariable" part="payload"
    query="/client:GetCustomerAccountInformationProcessResponse/client:customer/client:accounts/client:account[$Var_Counter]/client:dueDate"/>
    </copy>
    I have been using this in my processes.

  • How to populate multi-cluster arrays using matlab code?

    Hi,
    I have an array of clusters containing two 'Double' elements in each cluster. I am looking for a method to populate this array using MATLAB code. I need around 1000 clusters in the array, so populating it using the front panel is not practical. There is also some calculation involved in deciding the value in each element. If there is an example or a method to do this, please point me in the right direction.
    Thanks

    altenbach wrote:
    Can you attach a typical file so we know that the structure is? It is easy to convert from any data structure to any other data structure. You could even read it as a 1D string array and parse each line into a cluster, for example. It all depends on how the fil is arranged. You could also read the file as a flat string and chop it up into the desired structure later.
    I have attached the .vi file. I need to convert the spreadsheet to an array of clusters, thats where I'm getting stuck. (The vi is an example from help libraries)
    That is the part where I need to change so that I can use a spreadsheet.
    Attachments:
    Buffered counter.vi ‏52 KB

  • Flex Tree component qestion.

    Hi, this might be a piece of cake for you guys. But I could not figure out how to expand the tree by default when you bring up your app.
    Thanks.
    K

    Set openItems
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Self Reference Model Class - How to populate using Entity Framework

    Hi,i have table in SQL Server named Employees as follows:
    EmployeeId lastName FirstName reportsTo
    1 Davolio Nancy 2
    2 Fuller Andrew NULL
    3 Leverling Janet 2
    4 Peacock Margaret 2
    5 Buchanan Steven 2
    6 Suyama Michael 5
    7 King Robert 5
    8 Callahan Laura 2
    9 Dodsworth Anne 5
    I would like to use Entity Framework to populate my Model Class .My model class looks as follows:
    public class Employees
        readonly List<Employees> _children = new List<Employees>();
        public IList<Employees> Children
            get { return _children; }
        public string FirstName { get; set; }
        public string LastName {get; set;}
    I want to use this class in ViewModel  to populate my TreeView control. Can anyone help me in order to define Linq to Entities in order to populate my model class Employees from table in SQL Server as defined. Thanks in advance.
    Almir

    Hello Fred,
    unfortunately it does not work, maybe I can be more specific about what I'm trying to get. I'm following Josh Smith's article on CodeProject related to WFP TreeView
    Josh Smith article. He has Class named Person with the following structure
    public class Person
    readonly List<Person> _children = new List<Person>();
    public List<Person> Children
    get
    return _children;
    public string Name { get; set; }
    The same is populated from Database class using method named GetFamilyTree() which look as follows:
    public static Person GetFamilyTree()
    // In a real app this method would access a database.
    return new Person
    Name = "David Weatherbeam",
    Children =
    new Person
    Name="Alberto Weatherbeam",
    Children=
    new Person
    Name="Zena Hairmonger",
    Children=
    new Person
    Name="Sarah Applifunk",
    new Person
    Name="Jenny van Machoqueen",
    Children=
    new Person
    Name="Nick van Machoqueen",
    new Person
    Name="Matilda Porcupinicus",
    new Person
    Name="Bronco van Machoqueen",
    new Person
    Name="Komrade Winkleford",
    Children=
    new Person
    Name="Maurice Winkleford",
    Children=
    new Person
    Name="Divinity W. Llamafoot",
    new Person
    Name="Komrade Winkleford, Jr.",
    Children=
    new Person
    Name="Saratoga Z. Crankentoe",
    new Person
    Name="Excaliber Winkleford",
    I'm trying to figure out how should I write
    GetFamilyTree() method using Entity Framework in order to connect to my SQL Server database and populate this Person class as it was populated manually in Joshs Example. The table I'm using in SQL Server is described in
    my first post named Employees (it's self reference table)

  • Tree component in Flex 4

    Are there any known issues with the <mx:Tree component in Flex 4?
    We have upgraded from Flex 3 builder to Flex 4 builder. Everything works except any where we have used a tree component the data is no longer showing. Has there been a change in how to populate the Tree component? We populate the tree by setting the dataProvider with an ArrayCollection.

    @travr,
    I'm not aware of any big known issues in mx:Tree between Flex 3.x and Flex 4.x. What problems are you seeing, and can you reproduce the issue with a simple test case (if so, please post the simple test case here and we can take a look).
    This works in Flex 3.5:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:ApplicationControlBar dock="true">
            <mx:Button id="sdkVer" initialize="sdkVer.label = mx_internal::VERSION;" click="System.setClipboard(sdkVer.label);" />
        </mx:ApplicationControlBar>
        <mx:Tree id="tr" labelField="name" width="200" x="20" y="20">
            <mx:dataProvider>
                <mx:ArrayCollection>
                    <mx:Object name="1. One">
                        <mx:children>
                            <mx:Object name="1.1 One" />
                            <mx:Object name="1.2 Two" />
                        </mx:children>
                    </mx:Object>
                    <mx:Object name="2. Two">
                        <mx:children>
                            <mx:Object name="2.1 One" />
                        </mx:children>
                    </mx:Object>
                </mx:ArrayCollection>
            </mx:dataProvider>
        </mx:Tree>
    </mx:Application>
    And this seems to work in Flex 4.5/Hero beta:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx">
        <s:controlBarContent>
            <s:Button id="sdkVer" initialize="sdkVer.label = mx_internal::VERSION;" click="System.setClipboard(sdkVer.label);" />
        </s:controlBarContent>
        <mx:Tree id="tr" labelField="name" width="200" x="20" y="20">
            <mx:dataProvider>
                <s:ArrayCollection>
                    <fx:Object name="1. One">
                        <fx:children>
                            <fx:Object name="1.1 One" />
                            <fx:Object name="1.2 Two" />
                        </fx:children>
                    </fx:Object>
                    <fx:Object name="2. Two">
                        <fx:children>
                            <fx:Object name="2.1 One" />
                        </fx:children>
                    </fx:Object>
                </s:ArrayCollection>
            </mx:dataProvider>
        </mx:Tree>
    </s:Application>
    Peter

  • Select tree node in tree component

    hi,
    i am developing a web site which has a site map as a tree component, the sitemap is a inserted in a page fragment, users could click tree nodes to go to corresponding pages. also on other pages, i have next and previous buttons which allow users to navigate through pages. the question is how can i update the tree component when users navigate using the next and previous buttons so that the correct tree node is highlighted?
    i tried to use the selected property for the tree component, but it does not do anything.
    thanks,
    lee

    Hi,
    Duplicate thread of
    http://swforum.sun.com/jive/thread.jspa?threadID=64518
    MJ

  • Flex tree

    Hi. I have some problem with Flex tree component.
    When I have XML (1), then I have correct tree output
    folder
    -item
    -item
    But when I create something like(2) , then I will have folder
    XXX like item.
    How can I solve it ?

    hi theosa
    try these
    <folder label="XXX" isBranch="true"/>

  • Tree element: How to make nodes editable

    Is it possible to make the nodes of a Tree element (a design time element visible in the view editor) editable? Or is there a tree component that can be used via "component use" with which to accomplish that?
    I don't want to use a table with embedded TreeByKeyTableColumn or similar!

    Hi Klaus,
    It's not possible for a tree ui element. As you pointed out you could achieve it using a TreeBy* master column of a table. The ByNesting variant uses a similar context structure as a tree. In addition, using a table will enable scrolling - which is not possible for the Tree ui element.
    Best regards,
    Thomas

  • How to use Javascript array in the JSP

    hELLO Friends,
    I am creating an String array using the values
    in the list of a jsp page using Java script..
    How can I use this array in the same jsp
    file for processing...
    any help in this regard would be highly appreciated.
    thanks in Advance...
    ashish

    you cannot pass values from javascript to JSP without having to form-post to another JSP page.

  • How to use an Array

    Morning all,
    I am trying to setup an array of numbers however, by looking at the crystal reports help file, I cannot find out how to set one up.
    I have created a new formula and inserted
    Local NumberVar Array x := MakeArray (1, 2, 3, 4, 5);
    however, it says you cannot set a result to an array.
    I have also looked at the Array help, but Crystal shows a VB syntax instead of Crystal. (How helpful to show VB syntax in CR!)
    My question is how can you use an array in your report that it shows numbers 1-5?
    many thanks
    Kind Regards
    Jehanzeb

    The question is - what you want to do with this array. Your code is correct , beside that you need to return something from formula and that needs to be discrete value.
    Local NumberVar Array x := MakeArray (1, 2, 3, 4, 5);
    "test"

  • Flex 4, is it possible to populate a tree component with sqlite table data?

    is it possible to populate a tree component with sqlite table data?
    If it is, how would I go about doing this?
    Thanks
    Kristin

    Hi Mustafa,
    it is true, the function can return component as type. This is more for the scenario, when you want to recognize some component based on some checks, eg.
    if(something)
    return CHECKBOX_1;
    else
    return CHECKBOX_2;
    so, the use case exists for sure. But of course the application itself is static.
    where do you see a scenario for dynamic creation of components?
    The only one component which can instantiate new components is the SplitCellContainer, and this is restricted to the drag&drop action from Fragment Bookmark Gallery. And this is again restricted to containers, as Fragment can hold containers as parent component. Of course the container content will be created/instantiated as well (I have coded example with ComponentManager in the Community SDK: Second Functional Application with SDK Components (Online Composition v.2) blog).
    As far I know there is no function in SplitCellContainer which would "simulate" the drop of a Fragment today (perhaps worth an Idea on this?). Having that - the scenario would be possible. Today, this can be made partly - but the user would need to drag&drop a prepared fragment with the component.
    Anyway, the problems will start after the creation - then it would be require to have also functions to re-position the new created component in some other container - this would be complex probably.
    Karol

  • How to Flex tree control using folder click event  to pass coldfusion to get data from dynamiclly ?

    Hi friends.........
                Iam using flex tree control data coming from coldfusion file to display grid. As i click the tree folder to change the data from dynamic from grid.
    How to pass the folder id from coldfusion file.. Is it possible ?.. Means give any example please....
    Any One Help Me......
    With Regards.,
    Lingu.......

    When you set the dataProvider for your tree control, you actually pass an array or arraycollection or whatever to that property. The array contains objects coming from your server, right? Each object should contain a property with the folder id, something like:
    var arr:Array = [{id: 1, folderID: 34, name: "..."}, {id: 2, folderID: 4, name: "..."}, ...];
    Now, when you click an item in your tree or your dataGrid, you can access the folder id by:
    myTree.selectedItem.folderID
    Hope this helps
    Dany

Maybe you are looking for

  • Hard Drive Issues and Time Machine

    I have a Macbook Pro with a 500GB hard drive with a Bootcamp partition. While in on Mac side, the MBP slipped off the couch and hit the carpet (only like a half foot). I noticed things were running sluggish so I ran Onyx, which stated that the startu

  • How to create Infotype entry in table T777D

    Hi All, We have undergone Upgrade from 4.6C to ECC 6.0. Now we get an error while maintaining certain data infotype 0122 does not exists. I looked at the entries in table T777D in both the system. In older system the entry is there but not in the new

  • HOW TO ADJUST MY FRONT PANEL & ITS OBJECTS ACCORDING TO SCREEN RESOLUTION.

    Hai.. I want my fp to be visible in its standard form on all screen resolutions.I've used Maintain window prop for diff screen resolutions but it didnt work.Any Solution to this problem? 

  • Opening Time Machine Backup in Windows

    Hi, My MacBook recently had a harddrive failure for the second time in a year. I think I have everything backed up from it through a Time Machine external harddrive, although after reading some of the posts on iTunes and iPhoto backups I'm not so sur

  • Where is Changes.txt ?

    I have looked both here and in Metalink but the changes.txt, jinit_download.htm and jinit_tags.htm are not to be found anywhere with the 1.1.8.16 JInitiator release.