4 Replies Latest reply on Mar 21, 2008 9:19 PM by shermm

    Data binding to set filename using a date

    shermm
      I am new to Flex and after reading through the live docs and testing various ways I can't get this to work. I am using a DateField to allow the user to display a graph of data based on what date they pick. File names are in the format of 2008-03-18.xml. I successfully am setting the DateField text element to give me the correct format. What I haven't figured out is how to use it to bind the date file selected to the chart. I am using the mx:Model. I keep getting this error.

      "Data binding expressions not supported with attributes processed at compile time." Here is the portion of code. dF is the DateField id. How would I bind on the date I pick.

      public function setFile():String {
      return dF.text;
      }
      <mx:Model id="results" source="{setFile() + '.xml'}"/>
        • 1. Re: Data binding to set filename using a date
          camfieldaj Level 1
          Have you tried anything like this:

          public function setFile():String {
          var fname:String;
          fname = dF.text + '.xml';
          return fname;
          }
          <mx:Model id="results" source="{fname}"/>

          The example says source="{dF.text}" would be legal, but you need the extension on there, right?

          Later,

          Andy C.(never #)

          • 2. Re: Data binding to set filename using a date
            shermm Level 1
            quote:

            Originally posted by: camfieldaj
            Have you tried anything like this:

            public function setFile():String {
            var fname:String;
            fname = dF.text + '.xml';
            return fname;
            }
            <mx:Model id="results" source="{fname}"/>

            The example says source="{dF.text}" would be legal, but you need the extension on there, right?

            Later,

            Andy C.(never #)




            Yes, I need to add the .xml extension to the date that is chosen. Then it will generate the chart from the file name that was created through selecting the date. 2008-03-21.xml

            I tried your example, but I am still getting the message...Data binding expressions not supported with attributes processed at compile time.

            Here is the full code. Hmm sidenote Adobe page says us "Attach Code" to include any sampole code, but I see no button to do that.

            ?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%">
            <mx:Script>
            <![CDATA[
            private function formatDate(date:Date):String {
            return dfconv.format(date);
            }
            private function setFile():String {
            var fname:String;
            fname = dF.text + '.xml';
            return fname;
            }
            ]]>
            </mx:Script>
            <mx:Model id="results" source="{fname}"/>
            <mx:DateFormatter id="dfconv" formatString="YYYY-MM-DD"/>
            <mx:HBox width="100%">
            <mx:Label text="Pick a date to display:"/>
            <mx:DateField id="dF" labelFunction="formatDate"/>
            <mx:Button label="Display" click="setFile()"/>
            </mx:HBox>
            <mx:AreaChart id="areachart1" dataProvider="{results.NETWORKPULL}" showDataTips="true" width="100%">
            <mx:horizontalAxis>
            <mx:CategoryAxis categoryField="TIME"/>
            </mx:horizontalAxis>
            <mx:series>
            <mx:AreaSeries yField="TEMPZONE1" displayName="Temp"/>
            </mx:series>
            </mx:AreaChart>
            <mx:Label text="Label"/>
            <mx:Legend dataProvider="{areachart1}"/>

            </mx:Application>
            • 3. Re: Data binding to set filename using a date
              ntsiii Level 3
              For mx:Model (which I advise against using) or mx:XML, which I recommend, source="path" is *compile-time* operation. It "bakes" the xml into the swf.

              To change the source at run-time, use HTTPService. There are lots of examples of this available.

              Tracy
              • 4. Re: Data binding to set filename using a date
                shermm Level 1
                I am getting confused now. I found some examples of the HTTPService and changing it, but it doesn't give the full example of how to call the methods. I tried implementing it in my program, but I am getting some compile errors. How should I set this up. When the App loads I want the chart with nothing in it. I want to then pick a date and have it take that string dF.text and put it into the url and load the data.

                Here is the code I have so far that isn't ...


                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%">
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;
                import mx.rpc.http.HTTPService;
                import mx.rpc.events.ResultEvent;
                import mx.rpc.events.FaultEvent;
                private function formatDate(date:Date):String {
                return dfconv.format(date);
                }
                private var service:HTTPService;

                public function useHttpService(parameters:Object):void {
                service = new HTTPService();
                service.destination = "' http://192.168.2.195/thermdata'+dF.text+'.xml'";
                service.addEventListener("result", httpResult);
                service.addEventListener("fault", httpFault);
                service.send(parameters);
                }
                public function httpResult(event:ResultEvent):void {
                var result:Object = event.result.NETWORK;
                //Do something with the result.
                }

                public function httpFault(event:FaultEvent):void {
                var faultstring:String = event.fault.faultString;
                Alert.show(faultstring);
                }
                ]]>
                </mx:Script>
                <mx:DateFormatter id="dfconv" formatString="YYYY-MM-DD"/>
                <mx:HBox width="100%">
                <mx:Label text="Pick a date to display:"/>
                <mx:DateField id="dF" labelFunction="formatDate"/>
                <mx:Button label="Display" click="{useHttpService()}"/>
                </mx:HBox>
                <mx:AreaChart id="areachart1" dataProvider="{httpResult(event)}" showDataTips="true" width="100%">
                <mx:horizontalAxis>
                <mx:CategoryAxis categoryField="TIME"/>
                </mx:horizontalAxis>
                <mx:series>
                <mx:AreaSeries yField="TEMPZONE1" displayName="Temp"/>
                </mx:series>
                </mx:AreaChart>
                <mx:Label text="Label"/>
                <mx:Legend dataProvider="{areachart1}"/>

                </mx:Application>