0 Replies Latest reply on Mar 12, 2007 2:44 AM by asish_sam

    How to create ArrayColletion in mx:Script from <mx:Model id="results" source="/data/data.xml" />

    asish_sam
      How to create ArrayColletion in mx:Script from <mx:Model id="results" source="/data/data.xml" />

      Please see my code:

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

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

      <mx:Model id="results" source="/data/data.xml" />


      <mx:Script>
      import mx.collections.ArrayCollection;
      import mx.utils.ArrayUtil;
      import mx.controls.Alert;
      </mx:Script>
      <mx:ArrayCollection id ="dt1" source="{ArrayUtil.toArray(results.result)}"/>

      <mx:Script><![CDATA[

      [Bindable]
      public var expenses:ArrayCollection = dt1;
      [Bindable]
      public var expenses2:ArrayCollection = dt1;
      [Bindable]
      public var dp:ArrayCollection=expenses;
      public function changeDataProvider():void{
      Alert.show(expenses.toString());
      if (dp==expenses){
      dp=expenses2;
      }else{
      dp=expenses;

      }

      }

      ]]></mx:Script>




      <mx:Panel x="10" y="10" width="100%" height="378" layout="absolute">
      <mx:ColumnChart dataProvider="{dt1}" x="10" y="10" id="myChart" height="318" width="100%">

      <mx:horizontalAxis>
      <mx:CategoryAxis categoryField="month"/>
      </mx:horizontalAxis>
      <mx:series>
      <mx:ColumnSeries displayName="apple" yField="apple"/>
      <mx:ColumnSeries displayName="orange" yField="orange"/>
      <mx:ColumnSeries displayName="banana" yField="banana"/>
      </mx:series>

      </mx:ColumnChart>
      <mx:Legend dataProvider="{myChart}" x="481" y="10"/>
      </mx:Panel>
      <mx:Button x="284" y="416" label="Change Data" id="bt" click="changeDataProvider()" />


      </mx:Application>