Solved

Convert mxml array to as3

Posted on 2010-09-09
3
513 Views
Last Modified: 2012-05-10
Hello all,

How would I convert the array in this mxml page to pure as3? Thanks!

tone


<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/03/using-an-array-as-a-data-provider-in-a-flex-tree-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx: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;
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object name="One">
            <mx:children>
                <mx:Array>
                    <mx:Object name="Two" />
                    <mx:Object name="Three" />
                    <mx:Object name="Four">
                        <mx:children>
                            <mx:Array>
                                <mx:Object name="Five" />
                                <mx:Object name="Six" />
                            </mx:Array>
                        </mx:children>
                    </mx:Object>
                    <mx:Object name="Seven">
                        <mx:children>
                            <mx:Array>
                                <mx:Object name="Eight" />
                            </mx:Array>
                        </mx:children>
                    </mx:Object>
                    <mx:Object name="Nine" />
                </mx:Array>
            </mx:children>
        </mx:Object>
    </mx:Array>

    <mx:Tree id="tree"
            dataProvider="{arr}"
            labelFunction="tree_labelFunc"
            width="200" />

</mx:Application>

Open in new window

0
Comment
Question by:toneDigital
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 125 total points
ID: 33646220
Something like this:

        private var dgArray:ArrayCollection =
            new ArrayCollection([
               { name:'One',
                 children:
                 [ {name:'Two'},
                   {name:'Three'},
                   {name:'Four', children:[{name:'Five'}, {name:'Six'}]},
                   {name:'Seven', children:[{name:'Eight'}]},
                   {name:'Nine'}
                 ]
               }
            ]);
0
 
LVL 4

Assisted Solution

by:andreMariano
andreMariano earned 125 total points
ID: 33654582
Its actually pretty easy, you see, an Array, can have anything inside it, and to define an array inside another one you can just do this "[ parameters ]" that is the same that "new Array( parameters )"
so:

var array:Array = new Array ( obj,[obj2,obj3,[obj4,obj5]]);

this is the same that

 <mx:Array id="arr">
        <mx:Object id="obj1">
            <mx:children>
                <mx:Array>
                   <mx:Object id="obj2">
                     <mx:Object id="obj3">
                      <mx:children>
                            <mx:Array>
                                <mx:Object id="obj4" />
                                <mx:Object id="obj5" />
                            </mx:Array>
                        </mx:children>
                </mx:Array>
             </mx:children>
    </mx:Array>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 33689166
thanx 4 axxepting
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now