0 Replies Latest reply on Jun 5, 2007 1:08 PM by Ario51

    Using object ID as variable name in ActionScript

    Ario51
      I'm using Flex with charting and having a problem with the Flex Development IDE. Here's a simplified version of the MXML code for the app:

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script source="Chart.as"/>
      <mx:Panel>
      <mx:LineChart>
      <mx:horizontalAxis>
      <mx:DateTimeAxis id="xAxis" dataUnits="days"/>
      </mx:horizontalAxis>
      <mx:verticalAxis>
      <mx:LinearAxis title="myTitle"/>
      </mx:verticalAxis>
      <mx:series>
      <mx:LineSeries yField="val" xField="time"/>
      </mx:series>
      </mx:LineChart>
      </mx:Panel>
      </mx:Application>

      The problem is that when I try to access the DateTimeAxis object using its ID as a variable name in the linked ActionScript, the compiler throws this error: "1120: Access of undefined property xAxis." Here's the relevant portion of the simplified code:

      import mx.charts.DateTimeAxis;
      public function changeResolution(event:Event):void
      {
      xAxis.dataUnits = 'months';
      }

      However, when I change "xAxis" to "this['xAxis']", it compiles and works, so I know I've got the ID typed in correctly. Furthermore, I have other objects in the MXML (not shown--specifically, an HTTPService object) which I *can* access in the desired way. Does anyone have any idea why this is? (Sorry if the code indentation gets lost when I post.)