Flash CS4教程:利用遮罩功能及添加代码来制作切换放大菜单效果

2019-10-08 12:03:51刘景俊

Flash CS4制作切换放大菜单效果,PS教程,思缘教程网

图9-11 发布效果

(6)下面创建动态文本对象,为按钮添加文字。第39~47代码创建一个不能被选择且禁止接收鼠标消息的动态文本,并设置样式和文本位置。其中第42行代码禁止接收鼠标事件(如指针经过或单击等事件);第43行代码是设置字体样式并调用 defaultTextFormat()方法,该方法返回一个文本格式对象(TextFormat),然后赋给defaultTextFormat属性(指定应用于新插入文本的格式)。

AS3代码

        var X:Number = Math.cos(radians) * R;   
        var Y:Number = Math.sin(radians) * R;   
  
        _mc.x = X;   
        _mc.y = Y;   
    }   
    var _text:TextField = new TextField();   
    _text.width = _text.height = 40;//因为默认情况下宽高都为100   
    _text.selectable = false; //文字不被选择   
    _text.mouseEnabled = false; //指定此对象禁止接收鼠标消息   
    _text.defaultTextFormat = defaultTextFormat(); //设置字体样式   
    _text.text = i;   
    _text.x = -_text.textWidth/2 - 2; //设置字体位置   
    _text.y = -_text.textHeight/2;   
    _mc.addChild(_text); //字体添加到对应按钮中   
}   
  
function defaultTextFormat():TextFormat {   
    var format:TextFormat = new TextFormat();   
    format.font = "黑体";    
    format.color = 0xFFFFFF;   
    format.size = 20;   
    format.bold = true;   
    return format   
}   
  
function clickHandler(e:MouseEvent) {   
    var _mc:Sprite = e.target as Sprite;   
    newX = _mc.x;   
    newY = _mc.y;   
       
    Tweener.addTween(_mc, {x:0, y:0,scaleX:2, scaleY:2, time:1, transition:"easeInOutQuint"});   
    Tweener.addTween(container_mc.getChildAt(_length), {x:newX, y:newY,scaleX:1, scaleY:1, time:1, transition:"easeInOutQuint"});   
    _mc.mouseEnabled = false;   
    var mc:Sprite = container_mc.getChildAt(_length) as Sprite  
    mc.mouseEnabled = true;   
    container_mc.swapChildren(container_mc.getChildAt(_length),_mc);   
       
}