XML-assisted Flash interactive electronic map tagging place names

Source: Internet
Author: User
Tags range relative
Xml

In the last lecture we introduced the basic steps of making one of the simplest flash electronic maps (Flash interactive electronic Map production manual-Getting Started ). However, for large city maps with larger data volume, it is very inconvenient to create the place name tagging directly in the flash environment, so it is necessary to use the external data file to assist in the completion of the place name tagging work. 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 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:

<?xml version= "1.0" encoding= "Utf-8"?>
<countrydata>
<state id= "Range" >
<data>0-33</data>
<color>fed976</color>
</state>
<state id= "Range" >
<data>34-66</data>
<color>feb24c</color>
</state>
<state id= "Range" >
<data>67-99</data>
<color>fd8d3c</color>
</state>
</countrydata>


  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> Great Qing Lake </n><x>37</x><y>264</y></r>
<r><n> Ring </n><x>154</x><y>67</y></r>
<r><n> City </n><x>164</x><y>67</y></r>
<r><n> West </n><x>175</x><y>69</y></r>
<r><n> Road </n><x>184</x><y>72</y></r>
<r><n> Ring </n><x>289</x><y>101</y></r>
<r><n> City </n><x>297</x><y>107</y></r>
<r><n> East </n><x>309</x><y>114</y></r>
<r><n> Road </n><x>321</x><y>117</y></r>
</n><x>231</x><y>95</y></r> in <r><n>
<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>
</n><x>229</x><y>18</y></r> in <r><n>
<r><n> Heart </n><x>233</x><y>34</y></r>
<r><n> North </n><x>235</x><y>47</y></r>
<r><n> Road </n><x>234</x><y>58</y></r>
<r><n>★, xx municipal Government </n><x>239</x><y>88</y></r>
<r><n> Town Theatre </n><x>271</x><y>84</y></r>
<r><n> Xinhua Bookstore </n><x>171</x><y>60</y></r>
<r><n> City </n><x>92</x><y>87</y></r>
<r><n> Ring </n><x>104</x><y>98</y></r>
<r><n> a </n><x>121</x><y>110</y></r>
<r><n> Road </n><x>134</x><y>124</y></r>
<r><n> Great Qing Lake tourist area </n><x>36</x><y>223</y></r>
<r><n>▲ Hundred feet Peak </n><x>124</x><y>30</y></r>
<r><n> Dongcheng San Tsuen </n><x>340</x><y>158</y></r>
<r><n> Nancheng Village </n><x>287</x><y>189</y></r>
<r><n>※ New Qi Garden </n><x>292</x><y>70</y></r>
<r><n> People's Park </n><x>144</x><y>42</y></r>
<r><n> Zoo </n><x>140</x><y>105</y></r>
<r><n> Dongcheng Plaza </n><x>342</x><y>73</y></r>
<r><n>※ Hundred Days Garden </n><x>92</x><y>55</y></r>
<r><n>※ Flower Peak Community </n><x>346</x><y>189</y></r>
<r><n> Gao San Tsuen </n><x>375</x><y>146</y></r>
<r><n>※ Flower Garden </n><x>210</x><y>185</y></r>
<r><n>▌ Building </n><x>219</x><y>111</y></r>
<r><n>▌ Good building </n><x>185</x><y>109</y></r>
<r><n>▌ Industrial Building </n><x>122</x><y>63</y></r>
<r><n>▌ Chenguang Business Building </n><x>265</x><y>62</y></r>
<r><n>▌ Overseas Chinese Electronics Building </n><x>209</x><y>84</y></r>
<r><n>▌ Good Mall </n><x>196</x><y>49</y></r>
</map>

Note: The <n> and </n> items are the x and y axes coordinates of the name;<x>122</x> and <y>63</y> for the place names, The value of its coordinates 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 = new XML ();// Creates an XML object
Road_xml.ignorewhite = true;//ignores spaces:
Road_xml.onload = function (Success:boolean): Void {
if (success) {//If the call succeeds
var childitems:array = road_xml.firstChild.childNodes;//define Data group
Var f=0;//define variable for MC depth
for var i: Number = 0; I <childItems.length; 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 values
_root.map_mc.bzmap_mc.createtextfield ("Road" +i, F, x, Y, 1, 1);//create name text
p= Eval ("Road" +i); Assigns the name of a text box variable to p
P.autosize = "Left";//Specifies the alignment of the text
P.text = Childitems[i].childnodes[0].childnodes[0].nodevalue; Get the name
f=f+1;//mc depth automatically add 1
}
}
}
Road_xml.load ("Road.xml");//Call 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.

After publication, the effect is as follows:


Call an external XML file add a place name

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.

In the next lecture, we'll learn how to assist in editing the annotation XML file in a debugging 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.