0 Replies Latest reply on May 14, 2007 12:07 PM by martinppp

    Problem accessing xml data

    martinppp
      When I tray to execute the following code after making a choice and clicking vote button, I got this error message:
      ==============================
      TypeError: Error #1010: A term is undefined and has no properties.
      at firstProjetct/vote()[C:\Java\Workspace-baq\sondageFlex\src\main\firstProjetct.mxml:38]
      at firstProjetct/___SetEventHandler2_handler()[C:\Java\Workspace-baq\sondageFlex\src\main\fi rstProjetct.mxml:90]
      ==============================
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="401" height="134" currentState="start_state">
      <mx:Script>
      <![CDATA[
      import mx.binding.utils.BindingUtils;
      import mx.utils.ObjectProxy;
      import mx.collections.ArrayCollection;
      [Bindable]
      private var votesAC:ArrayCollection = new ArrayCollection( [
      { Result:"Vote", Oui: 35, Non:39 } ]);

      [Bindable] public var resultName:XMLList;
      [Bindable] public var dataXML:XML =
      <Response>
      <Results>
      <Result name="null" value="2">
      <Index>index0</Index>
      </Result>
      <Result name="Oui" value="28"><Index>index1</Index></Result>
      <Result name="Non" value="111"><Index>index2</Index></Result>
      </Results>
      </Response>;
      // private var _opXML:ObjectProxy = new ObjectProxy(dataXML);

      public var choice:String;

      public function init():void{
      // BindingUtils.bindProperty(Resultats, "xField", _opXML, "Response.Results.Result.@name");
      }

      public function displayResult():void{
      myViewStack.selectedChild=result_view;
      }

      public function displayQuestion():void{
      myViewStack.selectedChild=question_view;
      }
      public function vote():void{
      trace(dataXML.toXMLString());
      resultName = dataXML.Result[1].Index;
      trace("name = "+ resultName);
      /**
      var request:URLRequest = new URLRequest(" http://localhost/xmlServlet/xmlservlet?command=surveyVoteCommand&surveyName=nbrAvocatsQueb ec&answer="+ choice);
      request.contentType = "application/xml";
      request.method = URLRequestMethod.GET;
      var loader:URLLoader = new URLLoader();
      loader.addEventListener(Event.COMPLETE, completeHandler);
      try
      {
      loader.load(request);
      }
      catch (error:ArgumentError)
      {
      trace("An ArgumentError has occurred.");
      }
      catch (error:SecurityError)
      {
      trace("A SecurityError has occurred.");
      }

      function completeHandler(event:Event):void
      {
      dataXML = XML(event.target.data);
      trace(dataXML.toXMLString());
      for each (var item:XML in dataXML..Result)
      {
      var itemName:String = item["@name"].toString();
      trace("Name = "+itemName);
      var itemValue:String = item["@value"].toString();
      trace("value = "+ itemValue);
      }

      }
      */
      }
      ]]>
      </mx:Script>
      <mx:states>
      <mx:State name="result_state">
      <mx:SetEventHandler target="{button1}" name="click" handler="currentState='result_state'"/>
      <mx:SetStyle target="{label1}" name="color" value="#bcbcc5"/>
      <mx:SetStyle target="{label1}" name="fontSize" value="12"/>
      <mx:SetProperty target="{label1}" name="width" value="369"/>
      <mx:SetProperty target="{label1}" name="x" value="16"/>
      <mx:AddChild relativeTo="{question_view}" position="lastChild">
      <mx:TitleWindow x="5" y="0" width="391" height="31" layout="absolute" fontSize="12" title="Sondage Éclair" fontFamily="Arial" color="#ffffff">
      </mx:TitleWindow>
      </mx:AddChild>
      </mx:State>
      <mx:State name="start_state">
      <mx:SetProperty target="{button1}" name="enabled" value="true"/>
      <mx:SetEventHandler target="{button2}" name="click" handler="vote()"/>
      <mx:SetProperty target="{button2}" name="enabled" value="true"/>
      <mx:SetStyle target="{Resultats}" name="fontFamily" value="Arial"/>
      <mx:SetEventHandler target="{radiobutton1}" name="click" handler="choice=&quot;Oui&quot;"/>
      <mx:SetEventHandler target="{radiobutton2}" name="click" handler="choice=&quot;Non&quot;"/>
      </mx:State>
      </mx:states>
      <mx:ViewStack x="0" y="33" id="myViewStack" width="100%" height="96">
      <mx:Canvas label="Question View" width="400" height="81" id="question_view">
      <mx:RadioButton x="22" y="40" label="Oui" groupName="radiogroup1" id="radiobutton1"/>
      <mx:RadioButton x="83" y="40" label="Non" groupName="radiogroup1" id="radiobutton2"/>
      <mx:Label x="22" y="10" text="Croyez-vous qu'il y a suffisamment d'avocats au Québec" width="355" id="label1"/>
      <mx:Button x="230" y="36" label="Votez" id="button2"/>
      <mx:Button x="297" y="36" label="Résultats" id="button1" enabled="true" click="displayResult()"/>
      </mx:Canvas>
      <mx:Canvas label="result_view" width="400" height="100%" id="result_view">
      <mx:BarChart x="20" y="10" id="Resultats" height="57" width="360" dataProvider="{dataXML}" showDataTips="true">
      <mx:verticalAxis>
      <mx:CategoryAxis categoryField="dataXML.Response.Results.Result" dataProvider="{dataXML}"/>
      </mx:verticalAxis>
      <mx:series>
      <mx:BarSeries yField="Result" displayName="Oui" xField="{dataXML.Response.Results.Result.(@name=='Oui').@['value']}" id="yes_value"/>
      <mx:BarSeries yField="Result" displayName="Non" xField="{dataXML.Response.Results.Result.(@name=='Non').@['value']}" id="no_value"/>
      </mx:series>
      </mx:BarChart>

      <mx:Legend dataProvider="{Resultats}"/>
      <mx:Button x="326" y="68" label="Votez" click="displayQuestion()" enabled="true"/>
      </mx:Canvas>
      </mx:ViewStack>
      <mx:Label x="0" y="0" text="Sondage Éclair" width="401" height="31" fontFamily="Arial" fontSize="20" color="#ffffff" id="label2"/>
      </mx:Application>

      ================
      I have problem accessing mxl data. I try many different examples and always got errors.

      Martin