Viewers: in countries Watching now:
In ActionScript 3.0 in Flash Professional CS5 Essential Training, Todd Perkins shows Flash designers how to incorporate ActionScript code into their projects and create interactive presentations and applications. The course includes a review of ActionScript language basics and the object-oriented programming (OOP) methodology, a tour of those Flash Professional CS5 features designed for developers, such as code hinting and the Code Snippets panel, and instructions on interacting with objects in the Library and placing code on the Timeline. Exercise files are included with the course.
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.
Find answers to the most frequently asked questions about ActionScript 3.0 in Flash Professional CS5 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
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.