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.
Once you've loaded XML data into Flash, you can work with that data using dot syntax. That's part of the benefit of XML being native in ActionScript 3.0. Here if I test the movie, you can see the XML data in the Output window. Let's take a look. So we have the images root element and then inside of there are image child elements, and each one of those elements has an attribute called file that has the file name of an image.
Now, let's say we want to access the file name of each image. Let's go back to our code and see how to do that. We'll just leave this code in a trace statement for now. We'll look at applying it to an actual image later on. So after imagesXML, you can type a dot and then type image. Now if you test the movie right now, here is what you'll get. Let's look in the Output window.
This actually gives us a list of all the child elements named image. So if we go back to our code, imagesXML represents that outer XML element. It has a child called image. When we reference image, Flash gives us a list of XML objects. The datatype of this list is called XMLList. It looks like this: XML in all caps, and then List with the capital L. If you want to know everything you can do with an XMLList, highlight it, and press F1 on your keyboard.
For now, we're going to look at something basic. Let's say we wanted to only access one object in a XMLList. After image, we can use square brackets, just like when you're working with an array. Remember that when you're working with an array, the first index is 0 and not 1. So type in 0, test the movie, and then we don't get anything. Now, that actually is not a bad sign. The reason for that is that the image element doesn't have any child elements, or child data at all.
So that's what we're actually seeing here. When we reference that image, we're seeing any children or any data that's inside of that image element, and right now there's not anything. The data that we want to access is inside of an attribute of that element. So again, we're accessing the first image element, and when we reference that image by itself, we don't see anything just yet. After the close square bracket, type a dot and then type an at symbol, this stands for attribute, and then type in the attribute name that you want to access.
That's called file. So inside of the image element, there is an attribute called file, and this is how you access it. Test the movie, and there is the data that we're looking for. So to review, when you create a new XML object with loaded data, that XML object represents the root of the loaded data. So in this case, it would be the images element. When you access child elements that have the same name, Flash gives you an XMLList, which is different from an XML object.
You can access single elements in that list by using square bracket notation and an index number, just like when you're working with an array. Once you have access to an element, you can access attributes of that element by typing a dot and then by typing at symbol and the attribute name. So by using this line of code, we're able to access specific names of files that we want to work with. So remember that E4X enables you to work with XML data using dot syntax.
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.