Join Todd Perkins for an in-depth discussion in this video Working with comments and processing instructions, part of ActionScript 3.0: Working with XML.
- View Offline
Now there may come a time when you want to access comment or processing instructions in your XML data. In this movie we will talk about how to do that. If you are following along I am working in 02_Comments_Processing.fla in the Chapter 3 folder. You can also just use the same file from the last exercise. Let's go to the first keyframe in the Actions Layer and open up the Actions panel. Now when Flash parses XML data, if you have not already told Flash not to ignore comments and processing instructions then comments and processing instructions will be ignored and you can't access them later on.
What we have to do is tell Flash not to ignore comments or processing instructions. The properties that handle whether you ignore comments and processing instructions are held as static properties of the XML class. So let's go all the way to the top of our code. I am going to type XML.ignore comments. This has a default value of True so if we just set that equal to False then we get our comments. And if we go to the next line and we type XML.ignore processing instructions and we set that equal to False as well and we test the movie, our XML string will display both our processing instructions and our comments.
Now let's say we wanted to access processing instructions or comments. One thing we can do is we are can refer to our XML object and we can type .Comment and comment is a method of the XML class that returns all the comments in our XML data. So I test the movie at this point and then you will see our comment. And if you want to see processing instructions it's essentially the same process. So test the movie and then we have our processing instructions there.
Now if you have multiple comments or multiple processing instructions you can access them similar to an array. The type of data that's returned when you run the processing instructions or comments method from the XML class is called an XMLList which is similar to an array of XML data. We are going to be talking about XMLList more as we go on throughout this chapter but there is a look at how to access comments and processing instructions if you ever need to.
- Understanding XML data
- Creating XML in ActionScript 3.0
- Working with external XML data
- Building a reusable RSS reader class
- Using PHP with XML
- Working with blogs
- Working with Flickr images using the Flickr API
- Working with podcasts