Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Loading files into Flash allows for smaller SWF file sizes and easier adjustments to your applications. XML is no exception. Let's take a look at how to load an external XML file into Flash. Select the first keyframe of the actions layer and open up the Actions panel. If you've loaded in a text file, then an XML file is exactly the same process. So we'll create a variable called imagesXML, in all caps. Datatype it to XML. We'll give this variable a value later on, once the data is loaded. And I am creating a variable here so that we can access it anywhere in our code.
Go to the next line and create a variable called xmlLoader, with a capital L. Datatype it to URLLoader. Set it equal to a new instance of the URLLoader class, exactly like what you would do with loading a text file. Go to the next line. Add an EventListener to the XML loader; xmlLoader.addEventListener. Event is going to be Event.COMPLETE, which means the file is finished loading. Type comma and a space. I'll run a method called xmlLoaded. Go down a few lines and create the xmlLoaded function.
Make sure it receives an Event object, which I'm going to call evt, with the datatype of Event, close up the parentheses, type colon, void, and some curly braces. And here we'll set the value of imagesXML equal to the loaded data. Remember that you can access the loaded data through the URLLoader's data property. So type xmlLoader.data. Now, what we're going to do is make sure that Flash treats this data as XML, because the code as it is could cause errors.
Data loads in similar to a string. So we want to make sure that this data is not a string, but XML. So to do that, I am going to type new, space, XML before xmlLoader.data. XML is going to be in all caps, then I'm going to wrap xmlLoader.data inside of parentheses. After that, we'll go to the next line, and we'll trace(imagesXML). And before we test the movie, we'll add one more important line of code to load the file. Make sure you do that below where you add the EventListener.
So we'll go down right to the next line, under adding the EventListener, and type xmlLoader, capital L, dot load, and in parentheses, we'll create a new URLRequest. URL is in all caps, Request is with a capital R, and in the parentheses after URLRequest, we'll type a string. So type quotes and then type the path to the XML file, which is assets/images.xml. Test the movie, and you should see the XML data inside of the Output window.
So to load an XML file, load the data just like you would load a text file. So use the URLLoader class. Once the data is loaded, pass in the data property of the URLLoader inside the parentheses of a new XML object. So make sure to tell Flash to treat that text data as XML data. So to load an XML file into Flash, use the URLLoader class, just like when you load a text file, and then set the loader's data property as the value inside of a new XML object.
That way Flash knows for sure that that text data can be treated as XML data.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99928 Viewers
56 Video lessons · 113024 Viewers
71 Video lessons · 81870 Viewers
131 Video lessons · 39286 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.