4 Replies Latest reply on Aug 24, 2006 7:43 AM by brainubmbc

    dataProviders and Components

    brainubmbc
      I made a simple component which makes an HTTPService call to a php script to get some information and populate a datagrid. it runs just fine.

      When I include it in another mxml file it runs just fine and pulls the data,. I was pretty excited that I got it to work (As you can tell I'm new to Flex.. trying out the developer's guide)... but when I select any of the items in the datagrid I get the following error: "The supplied DisplayObject must be a child of the caller"... only in the "TestProject.mxml" page do I get this error, not when I run the actual component by itself

      Here's the component "MyDataGrids.mxml" (with the domain name changes to protect the innocent):

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:HTTPService id="userRequest" url=" http://mydomain.com/test/testquery.php" useProxy="false"/>
      <mx:DataGrid id="dgUserRequest" dataProvider="{userRequest.lastResult.users.user}" creationComplete="userRequest.send();">
      <mx:columns>
      <mx:DataGridColumn headerText="User ID" dataField="userid"/>
      <mx:DataGridColumn headerText="User Name" dataField="username"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>

      Here's my mxml file that calls it (TestProject.mxml):

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:MyComps="*">
      <MyComps:MyDataGrids/>
      </mx:Application>

      Pretty basic, huh?

      Technically, it works the way I intended it. I just wanted a datagrid that pulled information from a mySQL database and could easily be re-used in different mxml files. It does just that so I feel *some* sense of accomplishment. I never intended the project to have any functionality when I selected a datagrid item, I just thought it was weird this error message popped up.

      There must be something about components that I'm not quite getting. Can anyone help? I've got a feeling there's probably something simple I need to do, but I'm missing.

      ->Brian

      --> Followup:

      I tried cropping the columns out of the component and adding them into the TestProject.mxml file as childs of the "MyDataGrids" object as such:

      <MyComps:MyDataGrids>
      <MyComps:columns>
      <MyComps:DataGridColumn headerText="User ID" dataField="userid"/>
      <MyComps:DataGridColumn headerText="User Name" dataField="username"/>
      </MyComps:columns>
      </MyComps:MyDataGrids>

      Same problem ;(

      Could it have something to do with the "creationComplete" and "dataProvider" attributes of the datagrid referring to the "userRequest" element?
        • 1. Re: dataProviders and Components
          ntsiii Level 3
          I am just starting with 2.0 myself, but in 1.5 it was actually illegal to create a component that extended the Application object. Instead, try extending, say, the Canvas object. That "child of caller" is suspicious.

          By extending, I mean using as the root tag of the component.

          Tracy
          • 2. Re: dataProviders and Components
            ntsiii Level 3
            And this is not really a Flex Builder question, so it should go in General Discussion.
            • 3. dataProviders and Components
              brainubmbc Level 1
              Sorry, I'll post similar questions in the other board from now on. If you don't mind, I have a followup which deals partly with Flex Builder itself (specifically at the end of this post dealing with error messages):

              By extending the Application object, you're referring to my <mx:Application> element being the rot node?

              Actually, I took out the Application element altogether and included the namespace atribute in the HTTPService and VBox objects, the component doesn't even work. I get an error message and the datagrid doesn't even build properly. With the following code:

              <mx:HTTPService xmlns:mx=" http://www.adobe.com/2006/mxml" id="userRequest" url=" http://versionnumber.inphonic.com/test/testquery.php" useProxy="false" />
              <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml">
              <mx:DataGrid id="dgUserRequest" creationComplete="userRequest.send();" dataProvider="{userRequest.lastResult.users.user}" >
              <mx:columns>
              <mx:DataGridColumn headerText="User ID" dataField="userid"/>
              <mx:DataGridColumn headerText="User Name" dataField="username"/>
              </mx:columns>
              </mx:DataGrid>
              </mx:VBox>

              I actually get an error on line one when trying to build which reads:

              "Multiple markers at this line:
              Encountered "<mx:HTTPService>" at line 1, column 154
              Encountered "<mx:HTTPService>" at line 1, column 154"

              Column 154 is actually the column after the closing ">" in line 1. There isn't even any whitespace after the ">" character so technically there IS NO column 154. Weird. It's also interesting how that last line repeats twice n the error message.

              Anywho.. are you suggestion I enclose everything in a "<mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml"></mx:Canvas>" root node?

              I gave that a shot, but I then get two problems... When I build the component I get a window popping up that says there are errors in my Project. The funny thing is, Builder doesn't show any red "X"'s by any lines of my code which is strange. I continue running/building the project anyways and the component doesn't even render. I get an error upon page load which says "A term is undefined as has no properties".

              Thanks for the assistance. I'll keep whacking away at it.

              ->B

              quote:

              Originally posted by: ntsiii
              I am just starting with 2.0 myself, but in 1.5 it was actually illegal to create a component that extended the Application object. Instead, try extending, say, the Canvas object. That "child of caller" is suspicious.

              By extending, I mean using as the root tag of the component.

              Tracy


              • 4. Re: dataProviders and Components
                brainubmbc Level 1
                ntsiii,

                You're right. All along it was the Application tag.

                I removed the application tag . Aparently there was still something wrong with my code that was causing some weird error, but I continued running the project anyways. I would get the same error message. I was just confused because I was unaware of the fact that if there was an error that caused your current mxml file not to compile properly into a .swf file, Flex Builder still opens up a browser but it shows the LAST .swf file that was properly compiled. I assumed it was still compiling properly.

                MORAL OF THE STORY TO ALL BEGINNINGERS (LIKE ME) WHO MIGHT READ THIS: Remember that when you run your project and you ignore an error and build anyways, when IE loads your project, it will be using the LAST working .swf file that was properly compiled and not neccessarily (actually most likely not) be using a compiled version of the current code.

                Thanks T,

                B