Archive for February, 2012

AS3: Volume Control

Actionscript
import flash.geom.Rectangle;
import flash.events.MouseEvent;
import flash.events.Event;

volControl_mc.progressFill_mc.width=190;

volControl_mc.progressBtn_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDrag);
function startDrag(e:MouseEvent):void{
	volControl_mc.progressBtn_mc.startDrag(true, new Rectangle(0,0,390,0));
	volControl_mc.progressBtn_mc.addEventListener(Event.ENTER_FRAME,scalePos);
		function scalePos(ev:Event):void{
			volControl_mc.progressFill_mc.scaleX = (volControl_mc.progressBtn_mc.x)/390;	
		}
}

volControl_mc.progressBtn_mc.addEventListener(MouseEvent.MOUSE_UP,stopDrag);
function stopDrag(e:MouseEvent):void{
	volControl_mc.progressBtn_mc.stopDrag();
}

AS3 Countdown

Actionscript
//user config settings
var countdownYear:Number= 2012;  //20xx
var countdownMonth:NUmber= 3; //1-12
var countdownDay:NUmber= 8; //1-31

date_txt.text= coutdownMonth +"/"+  countdownDay +"/"+ countdownYear; //date formatting

//events and time calculations

var static_date:Date= new Date(countdownYear, countdownMonth-1, countdownDay,0,0,0,0);

addEventListener(Event.ENTER_FRAME,fl_updateCountdown);


function fl_updateCountdown(evt:Event):void
{
	var now_date:Date= new Date();
	var nowCountdown: NUmber= static_date.time - now_date.time;

	var dayTill = ((((nowCountdown/1000)/60)/60)/24);
	var hoursTill= (((((nowCountdown/1000)/60)/60)/24)- Math.floor(dayTill))*24;
	var minTill= ((((((nowCountdown/1000)/60)/60)/24)- Math.floor(dayTill))*24- Math.floor(hoursTill))*60;
	var secTill= (((((((nowCountdown/1000)/60)/60)/24)- Math.floor(dayTill))*24 - Math.floor(hoursTill))*60 -Math.floor(minTill))*60;

countdown_txt.text= Math.floor(dayTill)+ "days"+ Math.floor(hoursTill) +"hrs" + Math.floor(minTill) +"min" + Math.floor(secTill) +"sec";
}

//end