9 Replies Latest reply on Jul 16, 2008 7:08 AM by invision-studios

    Populate TileList with XML data?

    invision-studios Level 1
      I'm trying to populate a TileList with data from an XML file. Any help is greatly appreciated.

      Here's a record from the XML file:

      <?xml version="1.0" encoding="iso-8859-1"?>
      <uniforms>
      <patternGroup>
      <groupID>kj02</groupID>
      <sport>Basketball</sport>
      <groupStyle>Basketball Uniform</groupStyle>
      <thumbnail>assets/basketball/thumbnailsPNG/kj02.png</thumbnail>
      </patternGroup>
      </uniforms>

      Here's the code for the application file:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="uniData.send()">

      <mx:Script>
      <![CDATA[
      [Bindable]
      private var uniXML:XMLList;

      private function uniHandler(evt:ResultEvent):void {
      uniXML=evt.result.patternGroup;
      }
      ]]>
      </mx:Script>

      <mx:HTTPService id="uniData" url="assets/uniforms.xml" result="uniHandler(event)" resultFormat="e4x" />

      <mx:TileList dataProvider="{uniXML}" labelField="groupID" iconField="thumbnail" width="400" height="400" />

      </mx:Application>

      The labelField works fine, but the iconField doesn't display an image.
      What am I missing here?

      thanks.
        • 1. Re: Populate TileList with XML data?
          EDendramis Level 1
          You might need the absolute path of the image.
          • 2. Re: Populate TileList with XML data?
            Gregory Lafrance Level 6
            Well this seems more like a workaround than a solution. I wonder how you can get iconField to work:
            • 3. Re: Populate TileList with XML data?
              Gregory Lafrance Level 6
              This seems to be how you use iconField:
              • 4. Re: Populate TileList with XML data?
                invision-studios Level 1
                If I provide the relative path thru an array, it works fine. I'm just missing something on the E4X syntax here, I believe.

                Thanks for the suggestion, tho.
                • 5. Re: Populate TileList with XML data?
                  invision-studios Level 1
                  Greg,

                  Your first post works and is a workaround, but it's a better solution for me.

                  I'm trying to avoid having to hard-code the image filenames into the MXML file, so this will work just fine with a minimum of additional work. The sample only had a single entry, but there are potentially hundreds of records in this XML.

                  Thanks for the quick reply.
                  • 6. Re: Populate TileList with XML data?
                    invision-studios Level 1
                    Okay, now for part two: to make the elements in my TileList clickable.

                    In an experiment with hard-wired icons, I was able to do this with the itemClick method.

                    Now, I'd like to use a node in my XML file to load a SWF onto the 'stage'. I can't figure out how to apply a 'data' attribute to the itemRenderer elements to make each item clickable.

                    Any ideas?

                    Sherm

                    • 7. Re: Populate TileList with XML data?
                      Gregory Lafrance Level 6
                      This almost works. I don't know if it is something in my SWF or something in my app. Don't know why this is giving this error:

                      TypeError: Error #1034: Type Coercion failed: cannot convert mx.core::FlexShape@4bd2df9 to mx.core.IUIComponent.
                      at mx.containers.utilityClasses::BoxLayout/measure()[E:\dev\3.0.x\frameworks\projects\framew ork\src\mx\containers\utilityClasses\BoxLayout.as:90]
                      at mx.core::LayoutContainer/measure()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core \LayoutContainer.as:388]
                      at mx.core::Application/measure()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\App lication.as:903]
                      at mx.core::UIComponent/measureSizes()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\cor e\UIComponent.as:5819]
                      at mx.core::UIComponent/validateSize()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\cor e\UIComponent.as:5765]
                      at mx.core::Container/validateSize()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\ Container.as:2657]
                      at mx.managers::LayoutManager/validateSize()[E:\dev\3.0.x\frameworks\projects\framework\src\ mx\managers\LayoutManager.as:559]
                      at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.0.x\frameworks\projects\frame work\src\mx\managers\LayoutManager.as:672]
                      at Function/ http://adobe.com/AS3/2006/builtin::apply()
                      at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.0.x\frameworks\projects\framework\sr c\mx\core\UIComponent.as:8460]
                      at mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.0.x\frameworks\projects\framework\src \mx\core\UIComponent.as:8403]
                      • 8. Re: Populate TileList with XML data?
                        invision-studios Level 1
                        Greg,

                        I appreciate the effort, but I'm trying to avoid hard-coding any arrays into my MXML page. That's why I needed the XML file in the TileList.

                        The code I posted above works fine, but it has the objects hard-coded.

                        I'm also trying to avoid having to parse the XML into an array. I would think if AS3 can handle an array, it should be able to handle the same data in XML format with E4X.

                        Sherm
                        • 9. Re: Populate TileList with XML data?
                          invision-studios Level 1
                          I got it! I think I was trying to make things too complicated.

                          Anyway, rather than a direct SWFLoader call from the itemClick() method, I call a function that loads the SWF (uniLoad). In the end, it's more flexible anyway. The only negative is that I have the path embedded in the XML data. I think I can fix that with another variable in the function.

                          Next step is to turn this into a component so I can re-use it for other 'sports'.

                          This is the function that does the trick:
                          private function uniLoad(evt:Event):void {
                          var swfToLoad:String = evt.currentTarget.selectedItem.artSWF;
                          swfLoader.load(swfToLoad);
                          }

                          Complete code below.

                          Greg, I really appreciate all your help on this. I'm really diggin' this E4X stuff!