Flex 让控件闪烁
效果预览:
看到天地会论坛有个让Flex里的控件闪烁效果,在那大侠的基础上稍稍加了几个参数进去,效果还挺好的~:)
ControlEffect.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" backgroundColor="0x000000">
- <mx:Script>
- <![CDATA[
- import com.tween.GlowTween;
- private function init():void
- {
- //对象,颜色,BlurX, BlurY, 内外发光
- new GlowTween(img1,0xFFFF00, 2, 10);
- new GlowTween(img2, 0xFF0000, 10, 20, true);
- new GlowTween(btn, 0x0000FF, 0, 5, true);
- new GlowTween(vbox, 0xFFFF00, 2, 20);
- }
- ]]>
- </mx:Script>
- <mx:Image x="20" y="18" id="img1" source="1.jpg" />
- <mx:Image x="250" y="18" id="img2" source="2.jpg" />
- <mx:Button label="Button" x="480" y="18" id="btn" />
- <mx:VBox id="vbox" x="480" y="50" width="100" height="80" backgroundColor="0xFFFF00" cornerRadius="10"><mx:Label text="VBox"/></mx:VBox>
- </mx:Application>
GlowTween.as
- 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;
- private var _blurMax:Number;
- private var _blurMin:Number;
- private var _inner:Boolean;
- public function GlowTween(target:InteractiveObject, color:uint = 0xFFFFFF, blurMin:Number = 2, blurMax:Number = 10 ,inner:Boolean = false)
- {
- _target = target;
- _color = color;
- _toggle = true;
- _blur = blurMin;
- _blurMin = blurMin;
- _blurMax = blurMax;
- _inner = inner;
- 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, onEnterFrame);
- _target.filters = null;
- _target = null;
- }
- private function startGlowHandler(event:MouseEvent):void
- {
- _target.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
- }
- private function stopGlowHandler(event:MouseEvent):void
- {
- _target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
- _target.filters = null;
- }
- private function onEnterFrame(event:Event):void
- {
- if (_blur >= _blurMax)
- {
- _toggle = false;
- }
- else if (_blur <= _blurMin)
- {
- _toggle = true;
- }
- _toggle ? _blur++ : _blur--;
- var glow:GlowFilter = new GlowFilter(_color, 1, _blur, _blur, 2, 2, _inner);
- _target.filters = [glow];
- }
- }
- }
发表于: 02-11-10 · 8 评论 » 2,037 次阅读
谢谢分享
六月 10th, 2010 at 17:38低调的飘过
八月 4th, 2010 at 10:04非常强悍。。
八月 9th, 2010 at 09:18非常强悍。。
八月 12th, 2010 at 04:40创造第一高楼
八月 15th, 2010 at 11:16飘过
八月 18th, 2010 at 10:38不错哦,谢谢哦。
八月 19th, 2010 at 11:33支持下,很强大
九月 1st, 2010 at 11:38