Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 595089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:01:27+00:00 2026-05-13T16:01:27+00:00

Gentlepersons, How does one initialize a collection instance from MXML in Flex/Actionscript? Background Let’s

  • 0

Gentlepersons,

How does one initialize a collection instance from MXML in Flex/Actionscript?

Background

Let’s assume that:

  • I’ve got three lists of number-name
    pairs.
  • The contents of each list never
    changes, but I may want to add new
    lists in future.
  • The user can choose which list to
    use.

I know how
to use MXML to define/initialize a
Flex UI component, but that is the
full extent of my XML experience.

Problem

How do I write a combination of XML declarations and Actionscript classes such that I can initialize each of my three lists from XML?

Please note that I am not trying to populate a Flex UI element (such as a DataGrid) with the various number-name pairs. I’m just trying to read the data into a plain old vanilla collection. (Once I’ve got my collections initialized, I can populate DataGrids or whatever at my leisure.) I can’t find any documentation of how to address this super-simple case. The documentation all assumes that I’m trying to do something much more complicated, such as accessing a remote database, which confuses the issue tremendously.

Thanks! 🙂

Jim Plamondon, Texas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:01:28+00:00Added an answer on May 13, 2026 at 4:01 pm

    There’s a few ways you can do this:

    Sample data set:

    <?xml version="1.0" encoding="UTF-8"?>
    <events type="array">
        <event>
            <date>12-50-99</date>
            <title>Event A</title>
            <location>San Diego, CA</location>
        </event>
        <event>
            <date>12-50-99</date>
            <title>Event B</title>
            <location>Healdsburg, CA</location>
        </event>
    </events>
    

    Flex 4

    XML Declarations

    Below are 3 ways to get data into XML or an ArrayCollection, both of which you can pass to your data provider.

    <?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">
    
        <fx:Declarations>
            <fx:XML id="data" source="events.xml"/>
    
            <fx:XML id="data2">
                <event>
                    <date>12-50-99</date>
                    <title>Event A</title>
                    <location>San Diego, CA</location>
                </event>
                <event>
                    <date>12-50-99</date>
                    <title>Event B</title>
                    <location>Healdsburg, CA</location>
                </event>
            </fx:XML>
    
            <fx:Declarations>
                <mx:ArrayCollection id="data3">
                    <fx:Object date="12-50-99" title="Event A" location="San Diego, CA"/>
                    <fx:Object date="12-50-99" title="Event B" location="Healdsburg, CA"/>
                </mx:ArrayCollection>
            </fx:Declarations>
        </fx:Declarations>
    
        <!-- then your views -->
        <mx:Button/>
    </s:Application>
    

    Flex 3 works the same, but you just remove the <fx:Declarations/> tags.

    If you want the data to be dynamic, I would just create a property for your ArrayCollection or XMLListCollection in the <mx:Script/> block in your view, say [Bindable] public var myData:ArrayCollection;, and load the data into that via XML. By keeping your data external (not hardcoding/embedding data into MXML), you don’t have to recompile, and it’s easier to add more and more.

    In order to do that, you’d either need to use URLRequest or HTTPService. HTTPService is basically an MXML wrapper around the URLRequest.

    Something like this pseudo code:

    <?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"
        initialize="loadData()">
        <fx:Script>
    
            import mx.collections.*;
    
            [Bindable] public var list1:IList;
            [Bindable] public var list2:IList;
            [Bindable] public var list3:IList;
    
            public function loadData():void
            {
                eventsService.load(); // loads, may take a few frames/seconds
            }
    
            public function updateData(result:Object, property:String):void
            {
                // this["list1"] = xml;
                this[property] = new XMLListCollection(result);
            }
    
        </fx:Script>
    
        <fx:Declarations>
            <mx:HTTPService id="eventsService"
                url="events.xml" 
                resultFormat="e4x"
                result="updateData(event.result, 'list1');"
                fault="trace('eventsService Error');"/>
        </fx:Declarations>
    
        <!-- then your views -->
        <mx:List dataProvider="{list1}"/>
    </s:Application>
    

    Let me know if that works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 437k
  • Answers 437k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your case statements should use the ids defined in your… May 15, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer Edit 2018: Since my 2010-2012-2014 answer, in 2015 Git for… May 15, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer WebSockets uses TCP, which is point to point, and provides… May 15, 2026 at 4:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.