6 Replies Latest reply on May 4, 2010 3:25 PM by mumcs01

    getItemAt(selectedIndex) out of range?

    mumcs01 Level 1

      So Im trying to use an xmllistcollection named subnetResults. According to debug variables its populated with 4 indexes. No matter what selectedindex is set to I get a runtime error in the browser of 'RangeError: Index '1' specified is out of bounds'.


      Am I using getItemAt correctly?


      import mx.rpc.events.ResultEvent;
        import mx.collections.ArrayCollection;

        public var selectedindex:int = 1;

        private function displaySubnet():void


        • 1. Re: getItemAt(selectedIndex) out of range?
          Flex harUI Adobe Employee

          Maybe you're calling to soon, before it has been filled with data.

          1 person found this helpful
          • 2. Re: getItemAt(selectedIndex) out of range?
            mumcs01 Level 1

            This is a very valid point... So right now I am populating my XMLList in my main component with an initialize() in the main application. Another XML component is then getting called to open up the form which uses this data. That Form component is using another initialize to dislaySubnet(). This may explain why 1 in 20 times it seems the data population works just fine.


            How do can I make sure that the initialize is complete, before another function occurs (Open the form component)?

            • 3. Re: getItemAt(selectedIndex) out of range?
              mumcs01 Level 1

              This is certainly the case. I had it run a blank page first, which gave it time to

              finish the loading, works great everytime. So I guess my question would be, how can I test if httpservice is still 'busy'

              in flex and/or action script so I can display something?

              • 4. Re: getItemAt(selectedIndex) out of range?
                -skitch- Level 1

                if the http service is still busy, you haven't been returned a call.  Look into callbacks

                1 person found this helpful
                • 5. Re: getItemAt(selectedIndex) out of range?
                  mumcs01 Level 1

                  callbacks... HUmmm ...




                  So basicly I need to do this.:



                  e4xway.request = { action: 'gd' };
                  e4xway.request = { action:'gc' };


                  The prokblem is, the first request runs, but I need to wait for the first reqest to complete before the second one goes as its referencing the same HTTPService.... I'll look into callbacks..


                  <mx:HTTPService id="e4xway" url=""
                  method="POST" showBusyCursor="true" resultFormat="e4x" result="xmlresultHandler(event)" fault="faultHandler(event)"/>



                  • 6. Re: synchronous HTTPService calls.
                    mumcs01 Level 1

                    I'm still struggling with callbacks: Below is a title window that has one field that I'm verifying.

                    From there I need to run an httpservice with an object, wait until its done, then run another httpservice, which from lots of searching on this forum should be handled by the ' service.addEventListener('result', reGetCfg); '. Basicly reGetCfg can't reference the parentDocument.. Why from a titlewindow can't I reference the parent caller. I've done this on other things?. Any ideas? Please? For lots of reasons I can't do do both calls in one call. I dont have control over the PHP side of the script.


                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
                    status="Add a Subnet" showCloseButton="false" borderAlpha="0.75" xmlns:com="val_classes.*" creationComplete="handleCreationComplete()">


                             import mx.rpc.events.ResultEvent;
                             import mx.rpc.http.HTTPService;      
                                import mx.managers.PopUpManager;
                                import mx.controls.Text;
                                import mx.controls.Alert;
                                import mx.rpc.events.ResultEvent;

                                private function handleCreationComplete():void {
                                private function reGetCfg(event:ResultEvent):void {
                                 parentDocument.returnState = parentDocument.getConfig.send( {action:'isr'} );
                                private function submit():void {
                                // Event handler for the OK button.
                                 var duplicateExists:int = 0;
                                 var i:int=0;
                                   for (i=0; i<parentDocument.subnetResults.length; i++) { 
                                    if ( parentDocument.subnetResults[i].subnet == subnettoAdd.text ) {
                                    if (duplicateExists != 0) {
                                     Alert.show("Subnet already exists!", "Message");
                                    } else {
                                     var sendObject:Object = { action: 'is', base: subnettoAdd.text };
                                     var service:HTTPService;
                                     service = new HTTPService();
                                     service.url = "";
                                     service.method = "POST";
                                     service.addEventListener(ResultEvent.RESULT, reGetCfg);


                    <com:IPAddressValidator source="{subnettoAdd}" property="text" valid="submit()"/>


                            <mx:Label text="Enter Subnet: "/>
                            <mx:TextInput id="subnettoAdd" width="100%" maxChars="15" restrict="0-9." />

                            <mx:Button id="ok" label="OK" click="validateNow()"/>
                            <mx:Button label="Cancel" click="PopUpManager.removePopUp(this);"/>