In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how Flex dynamically reads external XML files. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Flex reads external xml files dynamically
Xml files are used very frequently in Flex, because the operation of xml files in Flex is very simple. Sometimes we want to use xml as a configuration file to dynamically configure our system. Although FlexSDK provides a tag that can only be used in mxml files, and the source attribute of this tag can be read from external xml files, this approach causes the xml file to be embedded in the generated swf file. The result is that even if you modify the content of xml after release, it will have no effect on the program. This does not achieve the purpose of using external xml files. To achieve dynamic reading of xml files, you need to use the URLLoader class, which is located in the flash.net package.
First, create a URLRequest object
To use URLLoader to read external xml, you must call the load () function of URLLoader. One argument to this function is URLRequest, so you must first create a URLRequest object.
Varurl:URLRequest=newURLRequest ("TreeData.xml")
The parameter of URLRequest must be a valid url, because the file is in the same directory as the generated swf, so the file name is written directly. TreeData.xml is the file name of the external xml file. If you are in another directory, the file name must have a path.
Second, read external xml files
1. Create a URLLoader object.
Varloader:URLLoader=newURLLoader ()
2. To register event listeners for the newly created object, what we need to listen for is the Event.COMPLETE event, which represents the completion of reading the xml file.
Loader.addEventListener (Event.COMPLETE,onComplete)
OnComplete is the handler for the Event.COMPLETE event, which is called when the Event.COMPLETE event occurs.
3. Call the load function
Loader.load (url)
The parameter url is the URLRequest object you created earlier.
3. Event handling function onComplete
The complete definition of a function looks like this:
PrivatefunctiononComplete (event:Event): void {}
You have previously registered this function with the Event.COMPLETE event of the URLLoader object. This function is called when the Event.COMPLETE event occurs. The next question is how to get the xml data.
First, convert the target property of the parameter event of the onComplete function into a URLLoader object
Varresult:URLLoader=URLLoader (event.target)
Then convert the data property of this object to a xml object
Datas=XML (result.data)
In this way, the contents of TreeData.xml can be read into datas.
Postscript
Xml files can be read dynamically in this way. The content can be dynamically configured to provide a dynamic data source. As for how to apply it depends on your own needs.
The complete code:
Viewplaincopytoclipboardprint?
The content of the TreeData.xml used:
Viewplaincopytoclipboardprint?
Code supplement:
The code reads external xml files to provide data sources for the two Tree controls in two ways, and you can compare the differences between the two ways.
This is the end of this article on "how Flex dynamically reads external XML files". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.