XML-assisted Flash electronic map labeling place names

Source: Internet
Author: User
Tags range relative
Xml

For large-scale city map, directly in the flash environment to manually create a place name tagging content not only a huge workload, and maintenance update is very inconvenient, so you must use external data files to assist in the completion of the work of the name tag. Of course, there are a lot of ways to call data files, and we're here to introduce a simpler way to call an external XML data file in Flash.
Since XML files are involved, it is necessary to have an initial understanding of XML.

First, the initial knowledge of XML

1, what is XML?

XML is an abbreviation of the English Extensible Markup Language, which means extensible Markup language. XML is a set of rules that define semantic markup that divides documents into many parts and identifies them. It is also a Meta markup language, defined as a syntactic language for defining other semantic, structured markup languages related to a particular domain.

2. xml file Design

The following is an XML file structure, some of which are similar to HTML languages:



0-33
fed976


34-66
feb24c


67-99
fd8d3c

Second, Flash calls the method of XML file

actionscript2.0 in Flash There are more global functions and Method properties for calling XML, and the following is only described in this example:
1, the establishment of XML objects:
var myxml = new XML ();

2, referencing the XML file:
Myxml.load ("Data.xml");

3, Ignore space:
Myxml.ignorewhite = true;/default is False

4, processing the XML object load (Xml.load method)
Public Load (url:string): Boolean

Loads the XML document from the specified URL and replaces the contents of the specified XML object with the downloaded XML data. The URL is a relative URL and is invoked using HTTP. The load process is asynchronous; it does not end immediately after the load () method is executed.

When the load () method is executed, the loaded property of the XML object is set to False. After the XML data has been downloaded, the loaded property is set to True and the OnLoad event handler is invoked. The analysis is not started until the XML data has been completely downloaded. If the XML object previously contained any XML trees, they would be discarded.

You can define a custom function that executes when the OnLoad event handler function of an XML object is invoked.

5, processing XML object onload (xml.onload processing function)
onload = function (Success:boolean) {}

Called by Flash Player when you receive an XML document from the server. If the XML document is successfully received, the success argument is true. If the document is not received, or an error occurs when the response is received from the server, the success parameter is false. By default, the implementation of this method is not active. To override the default implementation, you must specify a function that contains the custom action.

Iii. Case-making

With a preliminary understanding of the basics of the above XML, we can complete the name tagging process immediately following the previous example:

1. Create an XML file for place name tagging:
First we want to create a name containing information about the need to mark the file, that is, including the names, geographical names coordinates and other basic information. In this example, we only create a demonstrative toponymic data file in the form of an XML file format, which reads as follows:

<?xml version= "1.0" encoding= "iso-8859-1"?
<map>
<r> <n> da Qing hu </n> <x> 264 </x> <y>, </y> </r>
<r> <n> ring </n> <x> 154 </x> <y> all </y> </r>
<r> <n> City </n> <x> 164 </x> <y> all </y> </r>
<r> <n> West </n> <x> 175 </x> <y> to </y> </r>
<r> <n> Road </n> <x> 184 </x> <y> a </y> </r>
<r> <n> ring </n> <x> 289 </x> <y>? </y> </r>
<r> <n> City </n> <x> 297 </x> <y> "</y> </r>"
<r> <n> East </n> <x> 309 </x> <y> 114 </y> </r>
<r> <n> Road </n> <x> 321 </x> <y> 117 </y> </r>
<r> <n> </n> <x> 231 </x> <y> [</y>]
<r> <n> Heart </n> <x> 232 </x> <y> 114 </y> </r>
<r> <n> South </n> <x> 233 </x> <y> 135 </y> </r>
<r> <n> Road </n> <x> 234 </x> <y> 158 </y> </r>
<r> <n> </n> <x> 229 </x> <y>-</y> </r>
<r> <n> Heart </n> <x> 233 </x> <y>-</y> </r>
<r> <n> North </n> <x> 235 </x> <y> all </y> </r>
<r> <n> Road </n> <x> 234 </x> <y> </y> </r>
<r> <n> ★ XX Municipal Government </n> <x> 239 </x> <y> (</y>)
<r> <n> City Cinema </n> <x> 271 </x> <y> </y> </r>
<r> <n> Xinhua Bookstore </n> <x> 171 </x> <y>? </y> </r>
<r> <n> City </n> <x> ("</x>") <y> </y>
<r> <n> Ring </n> <x> the </x> <y> "</y>" </r>
<r> <n> a </n> <x> 121 </x> <y> "</y> </r>"
<r> <n> Road </n> <x> 134 </x> <y> 124 </y> </r>
<r> <n> Great Qing Lake tourist area </n> <x> 223 </x> <y>-</y> </r>
<r> <n> ▲ Hundred feet </n> <x> 124 </x> <y> </y> </r>
<r> <n> Dongcheng Village </n> <x> 158 </x> <y> "</y> </r>
<r> <n> South Nancheng village </n> <x> 287 </x> <y> 189 </y> </r>
<r> <n> ※ New Qi garden </n> <x> 292 </x> <y> to </y> </r>
<r> <n> People's Park </n> <x> 144 </x> <y> to </y> </r>
<r> <n> Zoo </n> <x> 140 </x> <y> the </y> </r>
<r> <n> Dongcheng Plaza </n> <x> 342 </x> <y> to </y> </r>
<r> <n> ※ Hundred-Day garden </n> <x> "</x>" <y> "</y>" </r>
<r> <n> ※ Flower Peak cell </n> <x> 346 </x> <y> 189 </y> </r>
<r> <n> Gao Village </n> <x> 375 </x> <y> 146 </y> </r>
<r> <n> ※ Wind Taiwan flower Garden </n> <x> 210 </x> <y> 185 </y> </r>
<r> <n> ▌ City building </n> <x> 219 </x> <y> "</y> </r>
<r> <n> ▌ Building </n> <x> 185 </x> <y> 109 </y> </r>
<r> <n> ▌ Industrial Building </n> <x> 122 </x> <y>/</y> </r>
<r> <n> ▌ Chenguang Business building </n> <x> 265 </x> <y> "</y> </r>
<r> <n> ▌ Overseas Chinese Electronics Building </n> <x> 209 </x> <y> </y> </r>
<r> <n> ▌ Mall </n> <x> 196 </x> <y>, </y> </r>
</map>

Note: among The names of the names ; 122 and 63 are the x-axis and y-axis coordinates of the place names, and the results of their coordinate values will be explained in detail in a later instance.

2, the flash call code

Open Flash Professional, and then fill in the following ActionScript code in the timeline of the layer on the bottom map of the previous lecture:

var road_xml:xml = new XML (); /Build XML objects
Road_xml.ignorewhite = true; /Ignore spaces:
Road_xml.onload = function (Success:boolean): void {
if (success) {/If the call succeeds
var childitems:array = road_xml.firstchild.childnodes; /define data sets
var f=0; /define the variable of MC depth
for (var i:number = 0; I
var x=childitems[i].childnodes[1].childnodes[0].nodevalue/get X coordinate value
var y=childitems[i].childnodes[2].childnodes[0].nodevalue/get Y coordinate value
_root.map_mc.bzmap_mc.createtextfield ("Road" +i, F, x, Y, 1, 1); /Create a toponymic text
P=eval ("Road" +i); /Assign the name of the text box variable to p
P.autosize = "Left"; /Specifies the alignment of text
P.text = Childitems[i].childnodes[0].childnodes[0].nodevalue; /Get Names of names
f=f+1; /MC depth Automatic plus 1
}
}
}
Road_xml.load ("Road.xml"); /Invoke XML file:

Note: Where the path to the XML file uses a relative path, which is the path of the XML file relative to the Web page file that calls the Flash file, in this case, The Web page file that calls the Flash map file must be placed under the same path as the Road.xml file, or Flash will not be able to invoke the XML file.

In this way, Flash files only provide the basic structure of electronic maps, from the external road.xml file to provide place name tagging information, such as the name of the deletion, increase, error correction and other operations, only need to make corresponding changes to the XML file, and Flash files do not need to make any changes. This greatly reduces the maintenance, the workload of the update.

The above is the basic steps of flash calling an external XML file; Of course, we call the XML data file that is already edited in this example, and the coordinate value of obtaining the massive place name on the map can also be obtained in the flash environment.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.