当前位置:软件学习 > Flash >>

flash AS2地图缩放类实现代码

 代码如下 复制代码

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) / numOfBalls);
        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].onRollOver = 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].onRollOut = 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);
    //计算当前MC在画布的中心点位置。
    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 * delta / 100;
        _y -= omy * delta / 100;
        }
        _MW = mapMC._width;
        _MH = mapMC._height;
};
Mouse.addListener(myListener);

虽然求得了当前MC的中心点位置,分别为:DefaultX,DefaultY。但是在逻辑上就一直想不通,怎么以中心点布置当前MC。
Code片段:

 代码如下 复制代码

DefaultX = this._x + (_RW / 2);
DefaultY = this._y + (_RH / 2);

所以最后该地图的放大缩小是针对MC整体大小中心点缩放的,效果不佳。
Code片段:

 代码如下 复制代码

mapMC._x = -(mapMC._width / 2) + (_RW / 2);
mapMC._y = -(mapMC._height / 2) + (_RH / 2);

由于地图比画布要大很多,如果不以针对鼠标位置缩放,对用户体验不佳。
请问各位路过的,看贴的高手。AS2如何针对MC做鼠标缩放,并增加缓冲效果

实例下载

http://www.zzzyk.com/down/MapFla.part1.rar 第一部份
http://www.zzzyk.com/down/MapFla.part2.rar 第二部份

补充:flash教程,动画技术
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,