AS 3 ProgressBar----仿Win 7进条度


テストクラス:
package test
{
	import controlsEvents.ProgressBarEvent;
	import controlsEvents.TrackBarEvent;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ProgressBarTest extends Sprite
	{
		private var author:Label;
		private var pb:ProgressBar;
		private var tb:HorizontalTrackBar;
		private var bt:Button;
		private var isBindEnterFrame:Boolean=true;
		private var lb:Label;
		
		public function ProgressBarTest()
		{
			super();
			
			stage.color=0xccccbb;
			stage.frameRate=60;
			stage.align=StageAlign.TOP_LEFT;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			
			author=new Label();
			addChild(author);
			author.textColor=0x00ff00;
			author.fontSize=24;
			author.x=100;
			author.y=50;
			author.text=" :Jave.Lin";
			
			pb=new ProgressBar();
			addChild(pb);
			
			pb.x=100;
			pb.y=100;
			pb.width=300;
//			pb.height=5;
			
			pb.addEventListener(Event.ENTER_FRAME,onEnterFrame);
			pb.addEventListener(ProgressBarEvent.VALUE_CHANGED,onProgressValueChangedHandler);
			
			tb=new HorizontalTrackBar();
			addChild(tb);
			tb.width=300;
			
			tb.x=100;
			tb.y=150;
			
			tb.addEventListener(TrackBarEvent.VALUE_CHANGED,onValueChangedHandler);
			
			bt=new Button();
			addChild(bt);
			bt.x=100;
			bt.y=170;
//			bt.width=120;
			bt.isAutoSize=true;
			bt.text="[ ] [ ]";
			isBindEnterFrame=true;
			tb.mouseChildren=tb.mouseEnabled=!isBindEnterFrame;
			
			bt.addEventListener(MouseEvent.CLICK,onClick);
			
			lb=new Label();
			addChild(lb);
			
			lb.x=100;
			lb.y=120;
			
			tb.curValue=50;
		}
		
		private function onProgressValueChangedHandler(e:ProgressBarEvent):void
		{
			lb.text="progressValue:"+pb.curValue;
		}
		
		private function onClick(e:MouseEvent):void
		{
//			if(pb.hasEventListener(Event.ENTER_FRAME))// pb Event.EnterFrame , 
			if(isBindEnterFrame)
			{
				isBindEnterFrame=false;
				tb.mouseChildren=tb.mouseEnabled=!isBindEnterFrame;
				bt.text=" [ ]";
				pb.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
			}
			else
			{
				isBindEnterFrame=true;
				tb.mouseChildren=tb.mouseEnabled=!isBindEnterFrame;
				bt.text="[ ] [ ]";
				pb.addEventListener(Event.ENTER_FRAME,onEnterFrame);
			}
		}
		
		private function onValueChangedHandler(e:TrackBarEvent):void
		{
			pV=pb.curValue=tb.curValue;
			trace("pb.curValue",pb.curValue);
		}
		
		private var pV:Number=0;
		
		private function onEnterFrame(e:Event):void
		{
			pV+=.5;
			if(pV>=tb.maxValue)
			{
				pV=tb.minValue;
			}
			tb.curValue=pV;
		}
	}
}

実行例のダウンロード:ProgressBar.swf画像効果を実行する: