3 Replies Latest reply on Oct 23, 2006 8:18 AM by aBill

    XML Question

      I have a XML file with this information


      would it be possible for me to assign username or password to a Flex Variable and then display it in a label or how would i go about this?
        • 1. Re: XML Question

          I think HTTPService is your answer. It is better to look into documentation for details. http://download.macromedia.com/pub/documentation/en/flex/2/flex2_gettingstarted.pdf page 112
          It isn't long. Hope it help!

          William Chan
          • 2. Re: XML Question
            ForsakenBlade Level 1
            There are 2 problems with my script that I know of

            Problem #1:

            XML: (PHP FILLS THE $ variables)


            if I have CharacterInfo just have it show once it crashes so I have to have CharacterInfo repeat twice for some reason otherwise it gives an error.

            problem #2: I tried following the PDF, it tells you how to use variables for panels / datagrids but not how to create a variable in actionscript so then i could create an if statement and when the variable exists show a different .mxml file. I just need help with the converting the xml to a actionscript / flex variable.

            Here is the Code:

            <mx:HTTPService id="sendLogin" url=" http://www.chimeraonlinerpg.com/CO/XML/login.php" result="loginHandler(event)" useProxy="false" method="POST">
            <mx:request xmlns="">

            <mx:StringValidator id="accountValidator" source="{accountInput}" property="text" maxLength="15" minLength="5" triggerEvent="help" tooLongError="Account name may not contain more then 15 alphanumeric characters." tooShortError="Account name may not contain less then 5 alphanumeric characters."/>
            <mx:StringValidator id="passwordValidator" source="{passwordInput}" property="text" maxLength="15" minLength="5" triggerEvent="" tooLongError="Password may not contain more then 15 alphanumeric characters." tooShortError="Password may not contain less then 5 alphanumeric characters."/>

            <mx:DataGrid dataProvider="{loginData}"/>

            <mx:Form width="456" height="245">

            <mx:Panel width="100%" height="200" layout="absolute" title="Account Login">

            <mx:Label text="Password:" x="19" y="60"/>

            <mx:FormItem required="true" x="115" y="34" width="174">
            <mx:TextInput id="accountInput"/>

            <mx:Label text="Account Name:" x="19" y="34"/>

            <mx:FormItem required="true" x="115" y="64">
            <mx:TextInput id="passwordInput" displayAsPassword="true"/>

            <mx:Button id="buttonLogin" label="Login" click="sendLogin.send()" x="174" y="94"/>



            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            import flash.xml.XMLNode;

            private var tileData:ArrayCollection;

            private var loginData:ArrayCollection;

            private function resultHandler(event:ResultEvent):void {
            tileData = event.result.tiles.tile;


            private function loginHandler(event:ResultEvent):void {
            loginData = event.result.Character.CharacterInfo;


            • 3. XML Question
              aBill Level 1

              If your xml only has one child, you can just use Object instead of ArrayCollection. Inside a xml, only same name tags are convert to array, otherwise, it is an object. If it is an object, you cannot bind it to DataGrid. You have to create an Array (or ArrayCollection) to make it work. For example:
              <DataGrid dataProvider="{[sendLogin.lastResult]}" /> Using [ ] is a literal array
              In actionscript, you can loginData = new Array(); loginData.push(event.result);
              loginData = new ArrayCollection(); loginData.addItem(event.result);
              loginData = [ event.result] ; or loginData = new ArrayCollection([event.result]);

              ArrayCollection is a better choice in databinding, since it has propertyChangeEvent in adding or removing item. The binded target can do update when event fired.

              If you want the result is bindable, you can put makeObjectsBindable="true" in your HTTPService tag. Without specify the resultFormat in your HTTPService, it is deserialized as object. You don't have to convert if by your own!