Core Objects
Project 6 – Map measurements
During this quite simple project we will again use methods of Math object.
There is a fragment of the map displayed and the red "location" dot. If you move a mouse the distance between the dot and the mouse cursor is displayed. Dot is draggable, so you may measure the distance between any two points.
- Import the image of the map or… actually anything you want to measure and place it on the stage
- Add the dynamic text box and assign a variable way to it
- Create a draggable Movie Cilp. As you remember at first you need to create a button and then encapsulate it into the movie symbol. So button must be inside the movie symbol.
- Enter the code for the button event handler
on(press) { startDrag(this,false); _root.way._visible = false; } on(release) { stopDrag(); _root.way._visible = true; }The "dragging" part of the code is familiar to you. We also made the text box hidden when "red dot" is dragged – with the purpose to show the distance only when initial point of the distance stays still. -
Add the following code to the first (and the only) frame of the main timeline
onMouseMove = function(){ top = measurement._ymouse; left = measurement._xmouse; path = Math.round(Math.sqrt(Math.pow(top,2) + Math.pow(left,2)); }This code calculate the diagonal of the imaginable rectangle drawn between initial point and mouse You may adjust the measurement by dividing or multiplying "left" and "top" parameters by the constant value… now the all measurement are in pixels - Test the movie. The distance should appear in the textbox