stringHasValue of StringUtil, makeMorning and makeNight of DateUtil on AS3Corelib 0.92.1 help us handle strings and dates

Symbols-Tips-256x256 November 15 2008,  AS3Corelib 0.92.1 be released, As3corelib provides more helpful methods to help us handle strings and dates with the newest 0.92.1. They are stringHasValue of StringUtil, makeMorning and makeNight of DateUtil.

Search-256x256 Demo | DownloadDownload Full Project

Screenshot:

DateUtil

DateUtil-02

Methods:

1. stringHasValue()

public static function stringHasValue(s:String):Boolean

Specifies whether the specified string is either non-null, or contains characters (i.e. length is greater that 0)

Parameters:

s:String — The string which is being checked for a value

Returns:

Boolean

2. makeMorning()

public static function makeMorning(d:Date):Date

Converts a date into just after midnight..

Parameters:

d:Date

Returns:

Date

3. makeNight()

public static function makeNight(d:Date):Date

Converts a date into just befor midnight.

Parameters:

d:Date

Returns:

Date

The following is full source code :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	creationComplete="init();">
	<mx:Script>
		<![CDATA[
			import mx.utils.ObjectProxy;
			import com.adobe.utils.DateUtil;
			import mx.controls.Alert;
			import com.adobe.utils.StringUtil;

			[Bindable]
			private var strings:Array;

			[Bindable]
			private var date:Date;

			private function init():void
			{
				date = new Date();

				strings = new Array();

				var nullStr:ObjectProxy = new ObjectProxy();
				nullStr.name = "null string";
				nullStr.value = null;
				nullStr.hasValue = null;

				var emptyStr:ObjectProxy = new ObjectProxy();
				emptyStr.name = "empty string";
				emptyStr.value = "";
				emptyStr.hasValue = null;

				var nonemptyStr:ObjectProxy = new ObjectProxy();
				nonemptyStr.name = "nonempty string";
				nonemptyStr.value = "this is nonempty string";
				nonemptyStr.hasValue = null;

				strings.push(nullStr,emptyStr,nonemptyStr);
			}

			private function stringsHasValue():void
			{
				for each(var obj:ObjectProxy in strings)
				{
					obj.hasValue = StringUtil.stringHasValue(obj.value);
				}
			}
		]]>
	</mx:Script>
	<mx:DateFormatter id="df" formatString="YYYY-M-D H:N:S A"/>
	<mx:Panel
		width="100%"
		height="100%"
		title="corelib Demo">
		<mx:Form>
			<mx:FormHeading label="DateUtil"/>

			<mx:FormItem direction="horizontal">
				<mx:Button label="make night" click="date = DateUtil.makeNight(date)"/>
				<mx:Button label="make morning" click="date = DateUtil.makeMorning(date)"/>
			</mx:FormItem>

			<mx:FormItem direction="horizontal">
				<mx:TextInput text="{df.format(date)}" editable="false"/>
				<mx:Button label="reset" click="date = new Date();" />
			</mx:FormItem>

			<mx:FormHeading label="StringUtil"/>

			<mx:FormItem direction="vertical">
				<mx:DataGrid dataProvider="{strings}">
					<mx:columns>
						<mx:DataGridColumn dataField="name"/>
						<mx:DataGridColumn headerText="value" >
							<mx:itemRenderer>
								<mx:Component>
									<mx:Label text="{data.value == null?'[null]':data.value == ''?'[empty]':data.value}"/>
								</mx:Component>
							</mx:itemRenderer>
						</mx:DataGridColumn>
						<mx:DataGridColumn headerText="has value?">
							<mx:itemRenderer>
								<mx:Component>
									<mx:Label text="{data.hasValue==null?'unchecked':data.hasValue?'has value':'no value'}"/>
								</mx:Component>
							</mx:itemRenderer>
						</mx:DataGridColumn>
					</mx:columns>
				</mx:DataGrid>
				<mx:Button label="check" click="stringsHasValue()" />
			</mx:FormItem>
		</mx:Form>
	</mx:Panel>
</mx:Application>

Enjoy!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

Leave a Reply