14 Replies Latest reply on Apr 28, 2008 7:59 AM by levancho

    Loading XML data

    sandwicense Level 1
      In my ActionScript 3 code block, I am trying to get a TileList control to populate with images based on what node in the tree control the user selects. Of course the path to the .xml file will change because it will be up to the user to select which node. In the xml file that populates my tree control, I have an attribute called xmlLink. The direct path to the xml file is what is stored in this attribute. I keep getting this error:

      "1046: Type was not found or was not a compile-time constant: source"
      The line of code that this error is reacting to is the line below that is bold.

      I also tried to set the variable as string but I got a different error. It was something that it was being forced, so it is obviously wrong.

      I have compiled this code which help from various examples and using my beginner's knowledge of ActionScript 3 to piece it together. I htink I am on the right teack though.

      THank you in advance for your help! :)

      Here is the code I am presently working with:

      private function collectionSelect(event:Event):void {
      //PART 1a
      var inheritedLink:source = ""
      inheritedLink = event.currentTarget.selectedItem.@xmlLink;

      //PART 2a
      /*Define a new variable with "tileListASDP" as the Data
      Provider's Name*/
      tileListASDP = new XMLListCollection(inheritedLink);

      //PART 3a
      navAccordion.selectedIndex = 2;
        • 1. Re: Loading XML data
          atta707 Level 2

          var inheritedLink:String = ""
          inheritedLink = event.currentTarget.selectedItem.@xmlLink;

          and see if it works.

          do you have your custom class with the name 'source'?
          • 2. Re: Loading XML data
            sandwicense Level 1
            Thanks for replying.

            I tried string before, but it does not work either. Error Message:

            1067: Implicit coercion of value of sype String to an unrelated type XMLList.

            I also do not have a custom class named source. I have the script placed right into the mxml file.
            • 3. Loading XML data
              levancho Level 3
              I think you are trying to use source atttribute of XML tag?
              then define bindable variable :

              [Bindable] public var inheritedLink:String=""
              then defined xml tag and bind the variable :
              <mx:XML id="myXML" format="e4x" source="{inheritedLink}" />

              then you do :
              inheritedLink = event.currentTarget.selectedItem.@xmlLink;
              //and if for example xmlLink value is "mySuperAlbumsxml.xml"
              your xml object's source attribute will automatically change and will magically become :
              <mx:XML id="myXML" format="e4x" source="mySuperAlbumsxml.xml" />
              and finally when you do
              var tileListASDP:XMLListCollection = new XMLListCollection(myXML);
              you have shiny new xmlList Object.

              • 4. Loading XML data
                sandwicense Level 1
                I think this might be the solution, but I get this error: Data binding expressions not supported with attributes processed at compile time.

                The is targeting this lien of code:

                <mx:XML id="myXML" format="e4x" source="SOURCE.XML"/>
                • 5. Re: Loading XML data
                  levancho Level 3
                  you can bypass the binding and just use xml source attribute directly
                  myXML.source = event.currentTarget.selectedItem.@xmlLink;
                  var tileListASDP:XMLListCollection = new XMLListCollection(myXML);
                  • 6. Loading XML data
                    sandwicense Level 1
                    so if I do that, what do I set as the source="" of the <mx:XML> tag?

                    If I leave it blank, it will say: Problem parsing external XML file.
                    • 7. Re: Loading XML data
                      sandwicense Level 1
                      • 8. Loading XML data
                        levancho Level 3
                        yeah, mx:xml is not very FLEXible, actualy there is 0 (zero) API documentation about that tag, ...
                        you might want to do tha twith actionscript instead :

                        var externalXML:XML;
                        var tileListASDP:XMLListCollection;

                        then you do :

                        function loadMyXML(xmlname:String ) : void {
                        var loader:URLLoader = new URLLoader();
                        var request:URLRequest = new URLRequest(xmlname);
                        loader.addEventListener(Event.COMPLETE, onComplete);
                        // you can also add fault listener IO error etc ..
                        // to make sure xml can be loaded .

                        function onComplete(event:Event):void {
                        var loader:URLLoader = URLLoader(event.target);
                        externalXML = new XML(loader.data);
                        tileListASDP= new XMLListCollection(externalXML);
                        // do some mor estaff as you see fit

                        then you should be able to do :
                        • 9. Re: Loading XML data
                          sandwicense Level 1
                          At the ending of message you just posted, it says: "And then you should be able to do:"

                          Is that an error or did you mean to add something?
                          • 10. Re: Loading XML data
                            ntsiii Level 3
                            "source" in the XML tag is a compile time operation, so you can not use binding braces with it.

                            If you are loading your data at run-time do as levancho says, just use an XML typed varialbe to hold the data. Set it in a reault handler.

                            Levancho's example uses Loader, but I find HTTPService easier to work with. They do the same thing.

                            • 11. Re: Loading XML data
                              sandwicense Level 1
                              I get the following error....

                              1067: Implicit coercion of a value of type XML to an unrelated type XMLList.

                              ...for the line of code below:
                              tileListASDP= new XMLListCollection(externalXML);
                              • 12. Re: Loading XML data
                                sandwicense Level 1
                                I just tried setting it as an XMLList rather than XMLListColleciton and the error dissapeared. Is this ok in this situation?
                                • 13. Loading XML data
                                  sandwicense Level 1
                                  When I try to Click a node in the tree list I get this actionScript Error from Flash Player:

                                  Error: Unable to load ''.
                                  at mx.controls::SWFLoader/loadContent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\co ntrols\SWFLoader.as:1368]
                                  at mx.controls::SWFLoader/load()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\ SWFLoader.as:1211]
                                  at mx.controls::SWFLoader/commitProperties()[E:\dev\3.0.x\frameworks\projects\framework\src\ mx\controls\SWFLoader.as:1015]
                                  at mx.core::UIComponent/validateProperties()[E:\dev\3.0.x\frameworks\projects\framework\src\ mx\core\UIComponent.as:5670]
                                  at mx.managers::LayoutManager/validateClient()[E:\dev\3.0.x\frameworks\projects\framework\sr c\mx\managers\LayoutManager.as:791]
                                  at mx.controls.listClasses::TileBase/measureWidthOfItems()[E:\dev\3.0.x\frameworks\projects\ framework\src\mx\controls\listClasses\TileBase.as:1860]
                                  at mx.controls.listClasses::TileBase/commitProperties()[E:\dev\3.0.x\frameworks\projects\fra mework\src\mx\controls\listClasses\TileBase.as:2327]
                                  at mx.core::UIComponent/validateProperties()[E:\dev\3.0.x\frameworks\projects\framework\src\ mx\core\UIComponent.as:5670]
                                  at mx.managers::LayoutManager/validateProperties()[E:\dev\3.0.x\frameworks\projects\framewor k\src\mx\managers\LayoutManager.as:519]
                                  at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.0.x\frameworks\projects\frame work\src\mx\managers\LayoutManager.as:669]
                                  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]


                                  How can I make these functions only apply to nodes, not the folders/parent/root?
                                  • 14. Re: Loading XML data
                                    levancho Level 3
                                    Unable to load ''. -- > looks like you are telling the loader to load url of type '' (empty)

                                    make sure clicking on node passess correct parameter to loader function which shoul dbe I beleive xml file name right?