IT기술/Flex

flex 24 여러가지 data출력 (Array, ArrayCollection, XMLList, Model)

dobbby 2008. 11. 25. 12:18
반응형




<?xml version="1.0"?>
<!-- Simple example to demonstrate the List Control -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
    <mx:Script>
        <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.utils.ArrayUtil;
            [Bindable]
            public var selectedItem:Object;
   /*
            public var mystates:Array = [{label:"Alabama", data:"AL"}, {label:"Alaska", data:"AK"},
            {label:"Arizona", data:"AZ"}, {label:"Arkansas", data:"AR"}, {label:"California", data:"CA"},
            {label:"Colorado", data:"CO"}, {label:"Connecticut", data:"CT"}];
    
            public var mystates:ArrayCollection = new ArrayCollection([
            {label:"Alabama", data:"AL"}, {label:"Alaska", data:"AK"}, {label:"Arizona", data:"AZ"},
            {label:"Arkansas", data:"AR"}, {label:"California", data:"CA"}, {label:"Colorado", data:"CO"},
            {label:"Connecticut", data:"CT"}]);
            */
       ]]>
    </mx:Script>
    <mx:XMLListCollection id="xlc" source="{mystates}"/>
    <mx:XMLList id="mystates">

     <states>
      <label>Alabama</label><data>AL</data> 
     </states>
     <states>
      <label>Alask</label><data>AK</data> 
     </states>
     <states>
      <label>Arizona</label><data>AZ</data> 
     </states>
     <states>
      <label>Arkansas</label><data>AR</data> 
     </states>
     <states>
      <label>California</label><data>CA</data> 
     </states>
     <states>
      <label>Colorado</label><data>CO</data> 
     </states>
     <states>
      <label>Connecticut</label><data>CT</data> 
     </states>
    </mx:XMLList>
    <!--
    <mx:ArrayCollection id="ac" source="{ArrayUtil.toArray(mystates.state)}">
    </mx:ArrayCollection>

    <mx:Model id="mystates">
      <states>
        <state label="Alabama" data="AL"/>
        <state label="Alaska" data="AK"/>
        <state label="Arizona" data="AZ"/>
        <state label="Arkansas" data="AR"/>
        <state label="California" data="CA"/>
        <state label="Colorado" data="CO"/>
        <state label="Connecticut" data="CT"/>
      </states>
    </mx:Model>
 -->
    <mx:Panel title="List Control Example" height="75%" width="75%"
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
        <mx:Label text="Select a state to see its abbreviation."/>
        <mx:List id="source" width="100%" color="blue" dataProvider="{xlc}"
            change="this.selectedItem=List(event.target).selectedItem"/>
        <mx:VBox width="100%">
            <mx:Label text="Selected State: {selectedItem.label}"/>
            <mx:Label text="State abbreviation: {selectedItem.data}"/>
        </mx:VBox>
    </mx:Panel>
</mx:Application>
반응형