Select Page

Leading Zero Static function for digital clock

If you’ve ever created a digital timer or clock then you probably used something like this function. It adds a leading zero if the number is only one digit long. This means that if the minute value is ‘6’ then it will return ’06’. eg. 12:06:43

class com.sitedaniel.utils.StringUtil
{
	public function StringUtil(){}
	/**
	 * leadingZero
	 * Adds a zero if the length is less than 2
	 * @param	s
	 * @return  String with length of 2
	/*
	eg.
	input '0'  return '00'
	input '5'  return '05'
	input '24' return '24'
	*/
	public static function leadingZero(s:String):String {
		switch (s.length){
			case 1 :
				return "0" + s;
				break;
			case 2 :
				return s;
				break;
			default :
				return s;
				break;
		}
	}
}

AS2.0 DesignTool

Following up on an earlier post, here is the AS2.0 version of the dragToPosition X & Y coordinate tracer.

class com.sitedaniel.utils.Design
{
	public static function dragToPosition(mc:MovieClip):Void
	{
		mc.onPress = function():Void
		{
			startDrag(this, false);
		}
		mc.onRelease = function():Void
		{
			this.stopDrag();
			trace(this._x + ', ' + this._y);
		}
	}
}