3 Replies Latest reply on Nov 3, 2009 10:52 AM by rmorgan

    Newbie help

    rmorgan Level 1

      Hello,

       

      I currently have a CF application that I am attempting to rewrite in flex. I have been through a few tutorials and I am getting a basic understanding of some things but having a hard time getting things to work in a real life application. So, I hate to ask this but I dont know of any other way and if I could get this one little thing ironed out I think I could take it from there. Could someone show me how to get some dynamic radio buttons to work correctly.

       

      In my DB I have a list of affiliates(currently 6 affiliates) that I need to dynamically display with radio buttons. I am not really sure on how to do this on the MXML page, but as far as my CFC goes this is what I think I need.

       

      <cfcomponent>
      <cffunction name="getAffiliatetypes" access="public" returntype="query">
      <cfset var getAffiliatetype = "">
      <cfquery name="getAffiliatetype" datasource="broadcast">
      select affiliatetype_id, affiliatetype
      from affiliatetype

      order by affiliatetype asc
      </cfquery>
      <cfreturn getAffiliatetype>
      </cffunction>
      </cfcomponent>

       

      I hope this is enough and that it is clear enough to see what I am needing. TIA.

        • 1. Re: Newbie help
          camfieldaj Level 1

          Ok, you're a step ahead since you're used to coldfusion. Now, you just have to get used to separating out the interface from the data acquistion. I'm used to PHP and quite a few of my apps, all I had to do was comment out the PHP that produced HTML and add a function to send back XML to the requesting Flex app.

           

          Here's something from the help file that might interest you:

           

          <?xml version="1.0"?>
          <!-- repeater\DynamicLoop.mxml -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              initialize="catalogService.send();">

              <mx:HTTPService id="catalogService" url="assets/repeater/catalog.xml"
                      resultFormat="e4x"/>

              <mx:XMLListCollection id="myXC"
                      source="{catalogService.lastResult.product}"/>

              <mx:Repeater id="r" dataProvider="{myXC}">
                  <mx:RadioButton id="Radio" label="{r.currentItem.name}"
                          width="150"/>
              </mx:Repeater>
          </mx:Application>

           

          When the app initializes it calls the HTTPService; That returns XML that gets put into XMLListCollection; The Repeater takes

          myXC(XMLListCollection) and loops through it creating a RadioGroup with the Labels set to the values from the XML.

          • 2. Re: Newbie help
            rmorgan Level 1

            Thanks for the info. However, in doing all my reading, I think I would like to use the RemoteObject instead of  the HTTPService. Unless there is some reason that I should not use the RemoteObject tag, could I get a corresponding example using this instead of the HTTPService? Thanks.

            • 3. Re: Newbie help
              rmorgan Level 1

              Ok, here is what I have so far. It is taken from other examples from the web, and I am trying to modify it to fit my needs. As this is below the closest I have been able to get is one of the radio button labels displays [object Operation] instead of the actual label that I am intending.

               

              MXML:

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

               

              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
              <mx:Script>
                    <![CDATA[
                          import mx.controls.Alert;
                          import mx.rpc.events.FaultEvent;
                          import mx.rpc.Fault;
                          import mx.rpc.events.ResultEvent;
                          private function result(evt:ResultEvent):void { 
                                mygrid.dataProvider = evt.result;

               

                         }
                          private function fault(evt:FaultEvent):void {
                                Alert.show(evt.fault.message);                
                           
                          }
                    ]]>
              </mx:Script>

               

              <mx:RemoteObject id="mycfc" destination="ColdFusion" showBusyCursor="true" source="flexdemo.src.DemoCFC" result="result(event)" fault="fault(event)">

              </mx:RemoteObject>    
                    <mx:Button label="Button" click="mycfc.GetData()"/>

               

                    <mx:DataGrid id="mygrid"  width="487" height="169"/> <!-- This is just for display to make sure there is still data available -->
                    <mx:RadioButtonGroup id="affiliatetype"/>
                    <mx:RadioButton label="{mycfc.affiliatetype}" groupName="affiliatetype"/>
                    <mx:RadioButton label="Button 2" groupName="affiliatetype"/> <!-- this is just sitting here for no reason -->
              </mx:Application>

               

              CFC:

               

              <cfcomponent>
              <cffunction name="GetData" access="public" returntype="query">
              <cfset var getAffiliatetype = "">
              <cfquery name="getAffiliatetype" datasource="broadcast">
              select affiliatetype_id, affiliatetype
              from affiliatetype
              order by affiliatetype asc
              </cfquery>
              <cfreturn getAffiliatetype>
              </cffunction>
              </cfcomponent>