`
nlslzf
  • 浏览: 1028145 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Actionscript 3 实现控件 闪烁效果

    博客分类:
  • flex
阅读更多
http://bbs.actionscript3.cn/thread-26116-1-1.html
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                layout="absolute"
                                initialize="glintEffect1()"
                                 backgroundGradientAlphas="[1.0, 1.0]"
                                  backgroundGradientColors="[#400040, #400040]">
        <mx:Script>
                <![CDATA[
                        import flash.display.*;
                        import flash.text.TextField;
                        import com.tween.GlowTween;
                        private function glintEffect1():void
                        {
                                new GlowTween(image1, 0xFFFF00);
                                new GlowTween(image2, 0x00FFFF);
                        }
                ]]>
        </mx:Script>
        <mx:Image x="69" y="29" id="image2" source="images/Sleek_XP_064.png" width="88" height="74"/>
        <mx:Image x="214" y="29" id="image1" source="images/Sleek_XP_026.png" width="84" height="74"/>

</mx:Application>

package com.tween
{
        import flash.display.InteractiveObject;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.filters.GlowFilter;

        public class GlowTween
        {
                private var _target:InteractiveObject;
                private var _color:uint;
                private var _toggle:Boolean;
                private var _blur:Number;

                public function GlowTween(target:InteractiveObject, color:uint=0xFFFFFF)
                {
                        _target=target;
                        _color=color;
                        _toggle=true;
                        _blur=2;
                        target.addEventListener(MouseEvent.ROLL_OVER, startGlowHandler);
                        target.addEventListener(MouseEvent.ROLL_OUT, stopGlowHandler);
                }

                public function remove():void
                {
                        _target.removeEventListener(MouseEvent.ROLL_OVER, startGlowHandler);
                        _target.removeEventListener(MouseEvent.ROLL_OUT, stopGlowHandler);
                        _target.removeEventListener(Event.ENTER_FRAME, blinkHandler);
                        _target.filters=null;
                        _target=null;
                }

                private function startGlowHandler(evt:MouseEvent):void
                {
                        _target.addEventListener(Event.ENTER_FRAME, blinkHandler, false, 0, true);
                }

                private function stopGlowHandler(evt:MouseEvent):void
                {
                        _target.removeEventListener(Event.ENTER_FRAME, blinkHandler);
                        _target.filters=null;
                }

                private function blinkHandler(evt:Event):void
                {
                        if (_blur >= 20)
                                _toggle=false;
                        else if (_blur <= 2)
                                _toggle=true;
                        _toggle ? _blur++ : _blur--;
                        var glow:GlowFilter=new GlowFilter(_color, 1, _blur, _blur, 2, 2);
                        _target.filters=[glow];
                }
        }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics