Using trace function to realize interactive map background quickly Mark place names

Source: Internet
Author: User
Tags client
function | backstage

In the last lecture, we introduced the display of place names by invoking an external XML file. In this talk, we explain how to use the trace function of the Flash ActionScript code to implement interactive map background to quickly mark the work of geographical names.

   Understanding the Trace function

First, let's take a look at the trace function;
We can use the Flash debug player to capture the output from the trace () function and display the results. Use this statement to record programmatic comments or display messages in the output panel when you test your SWF file. You can use the expression parameter to check whether a condition exists, or to display a value in the output panel. The trace () statement is similar to the alert function in JavaScript. You can use the Omit trace Actions command in the Publish Settings dialog box to remove the trace () action from the exported SWF file.

It is important to note that the trace () function only takes effect in the debug player, and that the SWF file running in Flash Player or HTML file cannot display the output after it is officially published; therefore, this is only a useful background for map developers.

Production steps:

1, create the callout button and dialogue window

  
First we create a "callout" button symbol, a movie clip named "INPUT_MC" as a dialog window, and a dynamic text box named "Input_txt" to manually enter the name of a place, as shown in Figure 1:

Figure 1 Creating a Callout dialog window

2, write the relevant ActionScript code

Open the action panel of the callout button and enter the following ActionScript code:

On (release) {//mouse is released to trigger
input_mc._visible = 1; Open the Annotations dialog window
}


Open the action panel of the Pickup Callout point button and enter the following ActionScript code:

On (release) {//mouse is released to trigger
_root.map_mc.onmousedown = function () {//When mouse is pressed the event var inputx = _xmouse;////////////////////////////
var inputy = _ymouse; Use variable inputy to record the Y-coordinate of the current mouse pointer}

}


   Note: the XY coordinates of the mouse pointer captured in the above code are indicative only, and are in fact far less simple in a practical map, because we usually place names on designated places, so we need to scale, move, and so on; and simply use _xmouse and _ Ymouse is unable to capture the correct coordinate value, must rely on _xscale, _yscale, _width, _hight, _x, _y and other attribute values to correct the error caused by Operation map. The relevant formulas cannot be used in this example because of different map structures. The following is the author in the production of the map of the relevant capture point of the formula, can only be used for conceptual reference;

_GLOBAL.BZX = Math.Round (15868.48* (_root._xmouse-_root.map_mc._x+825*_root.map_mc._xscale/100)/_root.map_mc._ XScale);

Capture X axis coordinates


_global.bzy = Math.Round (15868.48* (_root._ymouse-_root.map_mc._y+426*_root.map_mc._xscale/100)/_root.map_mc._ XScale);

Capturing y-axis coordinates


While capturing the coordinates of the pointer can also directly display a tag on the map, you can add the following code, with a red dot to indicate:

_root.map_mc.createemptymovieclip ("Dzpot_mc", this.getnexthighestdepth ()); Draw a dot
_root.map_mc.dzpot_mc.linestyle (2, 0xff0000, 100); Dot is red with a weight of 2
_root.map_mc.dzpot_mc.moveto (0, 0);
_root.map_mc.dzpot_mc.lineto (0, 0.1);
_root.map_mc.dzpot_mc._width = _root.map_mc.dzpot_mc._height = 1000/_root.map_mc._xscale; Resize a dot
_root.map_mc.dzpot_mc._x = _root.map_mc._xmouse; Dot coordinates coincide with capture point
_root.map_mc.dzpot_mc._y = _root.map_mc._ymouse; Dot coordinates coincide with capture point


Open the action panel of the Finish button and enter the following ActionScript code:

On (release) {//mouse is released to trigger
var inputname = input_txt.text//Name of the place entered under the variable InputName record
Race ("<r><n>" +inputname+ "</n><x>" +inputx+ "</x><y>" +inputy+ "</y></ R> "+/n);
Code that displays the XML file format in the output panel
}


3. Mark the place name in the debug player:

Click on the menu "Release Preview"/"Flash", open the debug player, in which the callout, as shown in Figure 2;


Figure 2 Callout in the debug player

So repeatedly, in the output panel will continue to output the corresponding XML file code, as shown in Figure 3;


Figure 3 Displaying output in the output panel in the debug player

   Note: Because this example can only take effect in the debug player, it cannot be demonstrated in the Web page. In this case, the developer of the map can quickly label the place name in the background. However, this is often limited to common road names or place names, and for a large number of companies, Shang and other geographical names information, developers are unable to do a lot of tagging, must be through other channels by the operator of the client's own online tagging. This must be done with the help of database and ASP, in the next lecture, we will learn flash+xml+asp to achieve the client's online name tagging function .



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.