The next line is a trace statement and it simply outputs the data of the xml file we just loaded. And this is it. You have learned how to load XML files in flash. Now you can use this method to load all kinds of data. You can store the positions of movieClips in your flash in the xml file and use the xml file to change the positions of elements.
Or maybe you can use the xml file to store the written content of you website. The possibilities of using XML data are endless and if you think carefully before developing a flash application then you can wisely implement external XML database to make your application more dynamic.
Found this Flash XML tutorial too hard? Check out Wix, an awesome free Flash website builder. Save my name, email, and website in this browser for the next time I comment.
The event we're dealing with here is the event of the XML being fully downloaded and introduced into Flash movie. This is the called the onLoad event. Each of of these functions are used on an XML instance.
For example:. Passing text like that is optional, so for this example it will just be omitted. Once an instance exists, you can define the onLoad callback function. The callback function, whenever you make it, always has to be called onLoad. Just like other event handlers, this is how Flash knows to call it when its needed, i.
Additionally, a success argument is passed into each onLoad when it fires. This will let you know if your XML has actually successfully loaded or not. However, use a valid url with a rock-solid internet connection and success will be true signifying the completion of XML being loaded into Flash and ready for use. Here, we'll make an onLoad function that simply traces the XML object when successfully loaded. Since onLoad is defined in the XML instance, this inside the function references the instance directly.
This is handled through the load method, the second of the 2 functions. It is worth noting that when you load external file like this, you should not make the assumption that the file is loaded immediately. Because Flash does not know how large the file is, it usually runs this kind of process in the background while the movie continues to run. However, Flash is thoughtful enough to notify us when the file is loaded by what is termed: event handlers.
We will implement onLoad code soon. Note: for this tutorial, the XML file must be located in the same domain as the swf file. Now that we know how to load the file, it won't be much of a use without knowing what to do with it.
But before we process the file, we need to know that the file is loaded. We do that by overriding the onLoad event handler with our own function which will process the XML file.
Our handler function is called processXMLData. So the code becomes:. This doesn't mean that you should always stop the movie after loading. It really depends on your movie. In my simple example, I do want to stop the movie because the movie can't do anything else until the file is loaded.
We will write the actual code for processXMLData a bit later; currently, it does nothing. The parameter success is a boolean value that indicates whether the file is successfully loaded or not. It will be false if the file is not found. New, let's see how to access the XML data. This reference can be accessed with the keyword " this. According to the diagram above, " this" has 1 child nodes, which is named "news. Let's extend the tree view and see. Sure enough, there they are.
The order is always the same as in the XML file. But why are all the nodeValue s null? This is the way the XML object in Flash works: the nodeValue for an element is stored as a child node. There it is. I suggest writing some code and try to access some of the elements. The debugger is very helpful here because you can see the tree view like above.
0コメント