Flash AS2 map scaling implementation code

Source: Internet
Author: User
Tags rar
The code is as follows: Copy code

Stop ();

Var DefaultX = 0;
Var DefaultY = 0;
Var DefaultValue = true;
Var _ C = mapMC. Content;
_ C. _ alpha = 0;

_ RW = Stage. width;
_ RH = Stage. height;
_ MW = mapMC. _ width;
_ MH = mapMC. _ height;

Var coordinate: XML = new XML ();
Coordinate. ignoreWhite = true;
Coordinate. load ("coordinate. xml ");
Coordinate. onLoad = function (success)
{
List = coordinate. childNodes [0]. childNodes;
For (g = 0; g <list. length; g ++)
    {
Var t = mapMC. attachMovie ("arrow", "a" + g, g + 1 );
T. angle = g * (Math. PI * 2)/numofbils );
T. _ x = (list [g]. attributes. x-(t. _ width-30) * 4;
T. _ y = (list [g]. attributes. y-(t. _ height-7) * 4;
T. swapDepths (-g );
ContentShow (g );
    }
};

Function ContentShow (num)
{
Var Vlist = coordinate. childNodes [0]. childNodes [num];
MapMC ["a" + num]. Onrolover = function ()
    {
This. gotoAndPlay (2 );
This. swapDepths (1 );
This. _ y = this. _ y-4;
New mx. transitions. Tween (_ C, "_ alpha", mx. transitions. easing. Regular. easeOut, 0,100,. 5, true );
_ C. _ x = this. _ x;
_ C. _ y = this. _ y-120;
_ C. _ Info. text = Vlist. attributes. alt;
};
MapMC ["a" + num]. Onrolout = function ()
    {
This. gotoAndPlay (1 );
This. swapDepths (-g );
This. _ y = this. _ y + 4;
New mx. transitions. Tween (_ C, "_ alpha", mx. transitions. easing. Regular. easeOut, 100, 0,. 5, true );
};
}

MapMC. onMouseDown = function ()
{
This. startDrag (false, 0, _ RH-_ MW,-_ MW + _ RW, 0, _ RW );
// Calculate the position of the current MC in the center of the canvas.
DefaultX = this. _ x + (_ RW/2 );
DefaultY = this. _ y + (_ RH/2 );
};
MapMC. onMouseUp = function ()
{
StopDrag ();
};

Var myListener: Object = new Object ();
MyListener. onMouseWheel = function (delta)
{
With (mapMC ){
Var omx = _ xmouse, omy = _ ymouse;
_ Xscale + = delta;
_ Yscale + = delta;
_ X-= omx x * delta/100;
_ Y-= omy * delta/100;
        }
_ MW = mapMC. _ width;
_ MH = mapMC. _ height;
};
Mouse. addListener (myListener );

The center point of the current MC is obtained, namely: DefaultX and DefaultY. However, the logic is hard to figure out how to arrange the current MC with the central point.
Code snippet:

The code is as follows: Copy code

DefaultX = this. _ x + (_ RW/2 );
DefaultY = this. _ y + (_ RH/2 );

In the end, the zoom-in and zoom-out of the map is aimed at the overall size and center of the MC, which is ineffective.
Code snippet:

The code is as follows: Copy code

MapMC. _ x =-(mapMC. _ width/2) + (_ RW/2 );
MapMC. _ y =-(mapMC. _ height/2) + (_ RH/2 );

Because the map is much larger than the canvas, the user experience is poor if you do not scale the mouse position.
I would like to ask you to pass. How does AS2 scale the mouse over MC and increase the buffer effect?

Download instance

First part of http://www.111cn.net/down/MapFla.part1.rar
Http://www.111cn.net/down/MapFla.part2.rar part 2

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.