PageRenderTime 36ms CodeModel.GetById 18ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/asutil/style/Glitter.as

http://asutil.googlecode.com/
ActionScript | 116 lines | 63 code | 13 blank | 40 comment | 8 complexity | 5db4a7b9066d3e25163bcd7f4e7e54fb MD5 | raw file
  1package asutil.style
  2{
  3	
  4	import asutil.construct.impl.Hashtable;
  5	
  6	import flash.display.DisplayObject;
  7	
  8	import mx.effects.Fade;
  9	import mx.effects.Sequence;
 10	/**
 11	* ????
 12	*/ 
 13	public class Glitter
 14	{
 15		/**
 16		 * ???
 17		 */ 
 18		public function Glitter(argObject:Object)
 19		{
 20			glitterTable = new Hashtable;
 21			//??????? ??? 
 22			if(null == argObject.glitterEles){
 23				throw new Error("Invaild glitter elemsnts.");
 24			}
 25			 this.glitterEles = argObject.glitterEles; 
 26				
 27			//????????????????2??????
 28			if(null != argObject.interval){
 29				this.interval = argObject.interval;		
 30  			}
 31  			
 32  			initEffect();
 33		}
 34		/**
 35		 * ????
 36		 */ 
 37		public function play():void{
 38		        var effSeq:Sequence = glitterTable.find(glitterEles) as Sequence;
 39		        if(  null == effSeq){
 40			    	//?????
 41		        	initEffect();
 42		        	//????
 43		        	effSeq = glitterTable.find(glitterEles) as Sequence;
 44		        }
 45		        	/**
 46		        	 * ?????play????
 47		        	 * ???play???flex???????????????
 48		        	 * targets???????????
 49		        	 * ?resume????????????
 50		        	 */ 	
 51				    effSeq.resume();
 52		}
 53		
 54		/**
 55		 * ????
 56		 */ 
 57		public function pause():void{
 58		        var effSeq:Sequence = glitterTable.find(glitterEles) as Sequence;
 59		        if(  null != effSeq){
 60		        	effSeq.pause();
 61			        //????alpha???1
 62			        var eleArray:Array = effSeq.targets;
 63					eleArray.forEach(function(ele:DisplayObject,index:int,eleArray:Array):void{
 64						ele.alpha = 1;
 65					})
 66		        }   
 67		}
 68		
 69		/**
 70		 * ??????????
 71		 */ 
 72		public function stop():void{
 73		        pause();
 74		        glitterTable.remove(glitterEles);
 75		}
 76		
 77		/**
 78		 * ???????????
 79		 */ 
 80		private function initEffect():void{
 81					//?? ??
 82					var eff1:Fade = new Fade;
 83					eff1.duration = this.interval;
 84					eff1.alphaTo = 0
 85					
 86					//?? ??
 87					var eff2:Fade = new Fade;
 88					eff2.duration = this.interval;
 89					eff2.alphaTo=1
 90					
 91					var effSeq:Sequence = new Sequence;
 92					effSeq.addChild(eff1);
 93					effSeq.addChild(eff2);
 94					effSeq.repeatCount = 0;
 95					 
 96					effSeq.targets = glitterEles;
 97					effSeq.play();
 98					effSeq.pause();
 99					glitterTable.add(this.glitterEles,effSeq);
100		}
101		
102		/**
103		 * ?????????
104		 */ 
105		private var glitterEles:Array;
106		/**
107		 * ???????1?
108		 */ 
109		private var interval:Number = 1000;
110		/**
111		 * ???????????global??
112		 */ 
113		private static var glitterTable:Hashtable;
114
115	}
116}