2 Replies Latest reply on Nov 5, 2007 12:46 AM by vij010

    Starting on with XML in Flex

    vij010
      Hi,

      Suppose I have an xml file, what are the steps I would need to display the node values of the xml document in combo selections in a flex form ? I am ok with flex, but it's http services and the like that I don't have a clue on. The help files are informative, but they are very vast and exhaustive, so much that I don't have a proper roadmap to start on from...

      Can anyone post some sample code ,or logic to get me started ?...like what classes I should use, RPC events etc.....
        • 1. Re: Starting on with XML in Flex
          atta707 Level 2
          HTTPService class is what you'll use to get the XML file from server. The url property of this class would point to the file on the server. send() method would send the request. result event listener would be fired once you receive the result and fault would be fired if it failed for some reason.

          <?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/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>



          ATTA
          • 2. Re: Starting on with XML in Flex
            vij010 Level 1
            Hi,

            Will test and let you know....in the mean while I have another question....Here's some code....

            <?xml version="1.0" encoding="utf-8"?>
            <!-- Simple example to demonstrate StringValidator. -->
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" height="502" width="576" layout="absolute">
            <!-- The best way to control form validation-->

            <mx:Script>
            <![CDATA[
            import mx.controls.Alert;
            import mx.validators.Validator;

            // Define the validator Array.
            private var myValidators:Array;

            private function initValidatorArray():void {
            myValidators=[fname, fmail];
            }
            ]]>
            </mx:Script>


            <mx:StringValidator
            source="{fname}"
            required="true"
            property="text"
            minLength="10"
            maxLength="100"
            />

            <mx:EmailValidator source="{fmail}"
            property="text"
            invalidCharError="Invalid Characters"
            invalidPeriodsInDomainError="Invalid Periods"
            missingAtSignError="No @ symbol"
            missingPeriodInDomainError="Missing Period"
            />
            <mx:Panel x="10" y="10" width="556" height="482" layout="absolute">
            <mx:TextInput x="188" y="53" id="fname"/>
            <mx:Label x="102" y="55" text="Enter Name :"/>
            <mx:TextInput x="188" y="83" id="fmail"/>
            <mx:Label x="56" y="85" text="Enter Email Address :"/>
            <mx:Button x="188" y="113" label="Submit" id="mySubmit" click="Validator.validateAll(myValidators)"/>
            </mx:Panel>
            </mx:Application>

            What I am trying to do is to create a small form ,where I test whether the user enters proper data, and show the user back through an alert.

            My question is:

            1. Since I am using in built validators, how do I specify my custom validation logic ?...I know I see it in the help files, but am unable to translate that into Flex code.