Flex 让控件闪烁

效果预览:

看到天地会论坛有个让Flex里的控件闪烁效果,在那大侠的基础上稍稍加了几个参数进去,效果还挺好的~:)

ControlEffect.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" backgroundColor="0x000000">
  3. <mx:Script>
  4.     <![CDATA[
  5.         import com.tween.GlowTween;
  6.         private function init():void
  7.         {
  8.             //对象,颜色,BlurX, BlurY, 内外发光
  9.             new GlowTween(img1,0xFFFF00, 2, 10);
  10.             new GlowTween(img2, 0xFF0000, 10, 20, true);
  11.             new GlowTween(btn, 0x0000FF, 0, 5, true);
  12.             new GlowTween(vbox, 0xFFFF00, 2, 20);
  13.         }
  14.     ]]>
  15. </mx:Script>
  16. <mx:Image x="20" y="18" id="img1" source="1.jpg" />
  17. <mx:Image x="250" y="18" id="img2" source="2.jpg" />
  18. <mx:Button label="Button" x="480" y="18" id="btn" />
  19. <mx:VBox id="vbox" x="480" y="50" width="100" height="80"  backgroundColor="0xFFFF00" cornerRadius="10"><mx:Label text="VBox"/></mx:VBox>
  20. </mx:Application>

GlowTween.as

  1. package com.tween
  2. {
  3.     import flash.display.InteractiveObject;
  4.     import flash.events.Event;
  5.     import flash.events.MouseEvent;
  6.     import flash.filters.GlowFilter;
  7.     public class GlowTween
  8.     {
  9.         private var _target:InteractiveObject;
  10.         private var _color:uint;
  11.         private var _toggle:Boolean;
  12.         private var _blur:Number;
  13.         private var _blurMax:Number;
  14.         private var _blurMin:Number;
  15.         private var _inner:Boolean;
  16.        
  17.         public function GlowTween(target:InteractiveObject, color:uint = 0xFFFFFF, blurMin:Number = 2, blurMax:Number = 10 ,inner:Boolean = false)
  18.         {
  19.             _target = target;
  20.             _color = color;
  21.             _toggle = true;
  22.             _blur = blurMin;
  23.             _blurMin = blurMin;
  24.             _blurMax = blurMax;
  25.             _inner = inner;
  26.             target.addEventListener(MouseEvent.ROLL_OVER, startGlowHandler);
  27.             target.addEventListener(MouseEvent.ROLL_OUT, stopGlowHandler);
  28.         }
  29.  
  30.         public function remove():void
  31.         {
  32.             _target.removeEventListener(MouseEvent.ROLL_OVER, startGlowHandler);
  33.             _target.removeEventListener(MouseEvent.ROLL_OUT, stopGlowHandler);
  34.             _target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
  35.             _target.filters = null;
  36.             _target = null;
  37.         }
  38.  
  39.         private function startGlowHandler(event:MouseEvent):void
  40.         {
  41.             _target.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
  42.         }
  43.  
  44.         private function stopGlowHandler(event:MouseEvent):void
  45.         {
  46.             _target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
  47.             _target.filters = null;
  48.         }
  49.  
  50.         private function onEnterFrame(event:Event):void
  51.         {
  52.         if (_blur >= _blurMax)
  53.         {
  54.             _toggle = false;
  55.         }
  56.         else if (_blur <= _blurMin)
  57.         {   
  58.             _toggle = true;
  59.         }
  60.         _toggle ? _blur++ : _blur--;
  61.         var glow:GlowFilter = new GlowFilter(_color, 1, _blur, _blur, 2, 2, _inner);
  62.         _target.filters = [glow];
  63.         }
  64.     }
  65. }
发表于: 02-11-10 · 8 评论 »  2,037 次阅读

8 评论 致 《Flex 让控件闪烁》

  1. 文翼 发表:

    谢谢分享

    六月 10th, 2010 at 17:38
  2. 低碳 发表:

    低调的飘过

    八月 4th, 2010 at 10:04
  3. emul 发表:

    非常强悍。。

    八月 9th, 2010 at 09:18
  4. hzliqiu 发表:

    非常强悍。。

    八月 12th, 2010 at 04:40
  5. 91526 发表:

    创造第一高楼

    八月 15th, 2010 at 11:16
  6. zhengliyuan 发表:

    飘过

    八月 18th, 2010 at 10:38
  7. kobezl 发表:

    不错哦,谢谢哦。

    八月 19th, 2010 at 11:33
  8. 下载 发表:

    支持下,很强大

    九月 1st, 2010 at 11:38

评论

兄弟,没有中文内容的评论一律过滤!