I have never liked Model, a personal problem, I know.

 

Below is an example using HTTPService, my best friend.  Debugging binding is hard, so I almost always use a result handler, again as below.  Note that it assumes the xml file in in an assets folder.  Change that if necessary.

 

Tracy

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

             creationComplete="dsVideos.send();">

 

<mx:Script><![CDATA[

  import mx.collections.XMLListCollection;

  import mx.rpc.events.ResultEvent;

 

            private function onResult(oEvent:ResultEvent):void

            {

              var xlcDP:XMLListCollection = new XMLListCollection(oEvent.result.titles.title);

              list1.dataProvider = xlcDP; //assign XML XMLList to data Provider

            }//onResult

           

            private function lfnConcat(item:Object):String

            {

              return (item.className + " (" + item.duration + " hrs.)");

            }//lfnConcat

 

]]></mx:Script>

  <mx:HTTPService id="dsVideos" url="" result="onResult(event)" resultFormat="e4x"/>

            <mx:List id="list1" labelFunction="lfnConcat" width="300"/>

</mx:Application>

 

-- videoTitles.xml --

<?xml version="1.0"?>

<root>

            <titles>

                        <title>

                                    <className>Flash User Experience Best Practices</className>

                                    <duration>4.25</duration>

                        </title>

                        <title>

                                    <className>Flash Professional 8 New Features</className>

                                    <duration>1.0</duration>

                        </title>

                        <title>

                                    <className>Flash Professional 8 Essential Training</className>

                                    <duration>11.5</duration>

                        </title>

                        <title>

                                    <className>Flash Professional 8 Beyond the Basics</className>

                                    <duration>10</duration>

                        </title>

                        <title>

                                    <className>Flash Professional 8 Video Integration</className>

                                    <duration>7.25</duration>

                        </title>

                        <title>

                                    <className>Photoshop CS2 and Flash 8 Integration</className>

                                    <duration>2.5</duration>

                        </title>

            </titles>

</root>

 

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of John Mazzocchi
Sent: Friday, July 21, 2006 2:58 AM
To: [email protected]
Subject: [flexcoders] Populating ComboBox from Model/XML

 

Hi, newbie question here ... just learning. I'm using Flex 2. There seem to be numerous errors and typos in the Adobe Flex Help files/PDFs and I'm hitting a snag here ...

What I'd like to do, to begin with, is to populate a ComboBox from an external XML file. The section in the help files called "Populating a ComboBox control using variables and models" seems pertinent, but the second part of example doesn't work.

The relevant code is this ...

<mx:Model id="myDP">
<obj>
<item label="AL" data="" w:st="on">Montgomery"/>
<item>
<label>AK</label>
<data>Juneau</data>
</item>
<item>
<label>AR</label>
<data>Little Rock</data>
</item>
</obj>
</mx:Model>

<mx:ArrayCollection id="stateAC" source="{myDP.obj.item}"/>

<mx:ComboBox dataProvider="{stateAC}"/>

Should I be using XML or XMLList instead? Later I'd like to have the dataProvider be from an external source (HTTPService or WebService), but I can't even get this simpler code to work. Any help appreciated. Thanks.

This email and any files transmitted with it may be confidential and are intended solely for the use of the individual or entity to whom they are addressed. This email may contain personal information of individuals, and be subject to Commonwealth and/or State privacy laws in Australia. This email is also subject to copyright. If you are not the intended recipient, you must not read, print, store, copy, forward or use this email for any reason, in accordance with privacy and copyright laws. If you have received this email in error, please notify the sender by return email, and delete this email from your inbox.

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





YAHOO! GROUPS LINKS




__,_._,___

Reply via email to