first commit

This commit is contained in:
2020-10-20 00:58:15 +02:00
commit 7f1b9bfca5
222 changed files with 56918 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import com.yahoo.astra.display.BitmapText;
import flash.display.Sprite;
import flash.text.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.PixelSnapping;
/**
* Used to measure dimensions for BitmapText objects.
*
* @author Tripp Bridges
*/
public class AxisLabelUtil
{
/**
* Returns the potential width of a string when rendered in a text field. Takes into account
* the <code>TextFormat</code> settings and the rotation.
*
* @param textValue The string that will be used.
* @param tf The TextFormat object that will be applied.
* @param rotation The rotation that will be applied
*
*/
public static function getTextWidth(textValue:String, tf:TextFormat, rotation:Number = 0):Number
{
rotation = Math.max(-90, Math.min(rotation, 90));
var textField:BitmapText = new BitmapText();
textField.selectable = false;
textField.autoSize = rotation < 0 ? TextFieldAutoSize.RIGHT : TextFieldAutoSize.LEFT;
if(tf != null) textField.defaultTextFormat = tf;
textField.text = textValue;
textField.rotation = rotation;
return textField.width;
}
/**
* Returns the potential height of a string when rendered in a text field. Takes into account
* the <code>TextFormat</code> settings and the rotation.
*
* @param textValue The string that will be used.
* @param tf The TextFormat object that will be applied.
* @param rotation The rotation that will be applied
*/
public static function getTextHeight(textValue:String, tf:TextFormat, rotation:Number = 0):Number
{
rotation = Math.max(-90, Math.min(rotation, 90));
var textField:BitmapText = new BitmapText();
textField.selectable = false;
textField.autoSize = rotation < 0 ? TextFieldAutoSize.RIGHT : TextFieldAutoSize.LEFT;
if(tf != null) textField.defaultTextFormat = tf;
textField.text = textValue;
textField.rotation = rotation;
return textField.height;
}
/**
* Returns the dimensions of a text field if rotated.
*
* @param textField The text field to be used
* @param rotation The rotation to be applied
*/
public static function getBitmapTextSize(textField:TextField, rotation:Number):Object
{
var spr:Sprite = new Sprite();
var bitmapDataText:BitmapData = new BitmapData(textField.width, textField.height, true, 0);
bitmapDataText.draw(textField);
var bm:Bitmap = new Bitmap(bitmapDataText, PixelSnapping.AUTO, true);
spr.addChild(bm);
spr.rotation = rotation;
return {width:spr.width, height:spr.height};
}
}
}
+362
View File
@@ -0,0 +1,362 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
/**
* A collection of utility functions for the manipulation and inspection of date and time values.
*
* @see Date
*
* @author Josh Tynjala, Allen Rabinovich
*/
public class DateUtil
{
/**
* The names of months in English. The index in the array corresponds to the value of the month
* in a date object.
*/
public static var months:Array = [
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
/**
* The number of days in January.
*/
public static const DAYS_IN_JANUARY:int = 31
/**
* The number of days in February on a standard year.
*/
public static const DAYS_IN_FEBRUARY:int = 28;
/**
* The number of days in February on a leap year.
*/
public static const DAYS_IN_FEBRUARY_LEAP_YEAR:int = 29;
/**
* The number of days in March.
*/
public static const DAYS_IN_MARCH:int = 31;
/**
* The number of days in April.
*/
public static const DAYS_IN_APRIL:int = 30;
/**
* The number of days in May.
*/
public static const DAYS_IN_MAY:int = 31;
/**
* The number of days in June.
*/
public static const DAYS_IN_JUNE:int = 30;
/**
* The number of days in July.
*/
public static const DAYS_IN_JULY:int = 31;
/**
* The number of days in August.
*/
public static const DAYS_IN_AUGUST:int = 31;
/**
* The number of days in September.
*/
public static const DAYS_IN_SEPTEMBER:int = 30;
/**
* The number of days in October.
*/
public static const DAYS_IN_OCTOBER:int = 31;
/**
* The number of days in November.
*/
public static const DAYS_IN_NOVEMBER:int = 30;
/**
* The number of days in December.
*/
public static const DAYS_IN_DECEMBER:int = 31;
/**
* The number of days in a standard year.
*/
public static const DAYS_IN_YEAR:int = 365;
/**
* The number of days in a leap year.
*/
public static const DAYS_IN_LEAP_YEAR:int = 366;
/**
* The number of days appearing in each month. May be used for easy index lookups.
* The stored value for February corresponds to a standard year--not a leap year.
*/
public static var daysInMonths:Array = [
DAYS_IN_JANUARY, DAYS_IN_FEBRUARY, DAYS_IN_MARCH, DAYS_IN_APRIL,
DAYS_IN_MAY, DAYS_IN_JUNE, DAYS_IN_JULY, DAYS_IN_AUGUST, DAYS_IN_SEPTEMBER,
DAYS_IN_OCTOBER, DAYS_IN_NOVEMBER, DAYS_IN_DECEMBER];
/**
* Determines the number of days between the start value and the end value. The result
* may contain a fractional part, so cast it to int if a whole number is desired.
*
* @param start the starting date of the range
* @param end the ending date of the range
* @return the number of dats between start and end
*/
public static function countDays(start:Date, end:Date):Number
{
return Math.abs(end.valueOf() - start.valueOf()) / (1000 * 60 * 60 * 24);
}
/**
* Determines if the input year is a leap year (with 366 days, rather than 365).
*
* @param year the year value as stored in a Date object.
* @return true if the year input is a leap year
*/
public static function isLeapYear(year:int):Boolean
{
if(year % 100 == 0) return year % 400 == 0;
return year % 4 == 0;
}
/**
* Gets the English name of the month specified by index. This is the month value
* as stored in a Date object.
*
* @param index the numeric value of the month
* @return the string name of the month in English
*/
public static function getMonthName(index:int):String
{
return months[index];
}
/**
* Gets the abbreviated month name specified by index. This is the month value
* as stored in a Date object.
*
* @param index the numeric value of the month
* @return the short string name of the month in English
*/
public static function getShortMonthName(index:int):String
{
return getMonthName(index).substr(0, 3);
}
/**
* Rounds a Date value up to the nearest value on the specified time unit.
*
* @see com.yahoo.astra.utils.TimeUnit
*/
public static function roundUp(dateToRound:Date, timeUnit:String = "day"):Date
{
dateToRound = new Date(dateToRound.valueOf());
switch(timeUnit)
{
case TimeUnit.YEAR:
dateToRound.year++;
dateToRound.month = 0;
dateToRound.date = 1;
dateToRound.hours = 0;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.MONTH:
dateToRound.month++;
dateToRound.date = 1;
dateToRound.hours = 0;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.DAY:
dateToRound.date++;
dateToRound.hours = 0;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.HOURS:
dateToRound.hours++;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.MINUTES:
dateToRound.minutes++;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.SECONDS:
dateToRound.seconds++;
dateToRound.milliseconds = 0;
break;
case TimeUnit.MILLISECONDS:
dateToRound.milliseconds++;
break;
}
return dateToRound;
}
/**
* Rounds a Date value down to the nearest value on the specified time unit.
*
* @see com.yahoo.astra.utils.TimeUnit
*/
public static function roundDown(dateToRound:Date, timeUnit:String = "day"):Date
{
dateToRound = new Date(dateToRound.valueOf());
switch(timeUnit)
{
case TimeUnit.YEAR:
dateToRound.month = 0;
dateToRound.date = 1;
dateToRound.hours = 0;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.MONTH:
dateToRound.date = 1;
dateToRound.hours = 0;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.DAY:
dateToRound.hours = 0;
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.HOURS:
dateToRound.minutes = 0;
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.MINUTES:
dateToRound.seconds = 0;
dateToRound.milliseconds = 0;
break;
case TimeUnit.SECONDS:
dateToRound.milliseconds = 0;
break;
}
return dateToRound;
}
/**
* Converts a time code to UTC.
*
* @param timecode the input timecode
* @return the UTC value
*/
public static function timeCodeToUTC(timecode:String):String {
switch (timecode) {
case "GMT", "UT", "UTC", "WET": return "UTC+0000";
case "CET": return "UTC+0100";
case "EET": return "UTC+0200";
case "MSK": return "UTC+0300";
case "IRT": return "UTC+0330";
case "SAMT": return "UTC+0400";
case "YEKT", "TMT", "TJT": return "UTC+0500";
case "OMST", "NOVT", "LKT": return "UTC+0600";
case "MMT": return "UTC+0630";
case "KRAT", "ICT", "WIT", "WAST": return "UTC+0700";
case "IRKT", "ULAT", "CST", "CIT", "BNT": return "UTC+0800";
case "YAKT", "JST", "KST", "EIT": return "UTC+0900";
case "ACST": return "UTC+0930";
case "VLAT", "SAKT", "GST": return "UTC+1000";
case "MAGT": return "UTC+1100";
case "IDLE", "PETT", "NZST": return "UTC+1200";
case "WAT": return "UTC-0100";
case "AT": return "UTC-0200";
case "EBT": return "UTC-0300";
case "NT": return "UTC-0330";
case "WBT", "AST": return "UTC-0400";
case "EST": return "UTC-0500";
case "CST": return "UTC-0600";
case "MST": return "UTC-0700";
case "PST": return "UTC-0800";
case "YST": return "UTC-0900";
case "AHST", "CAT", "HST": return "UTC-1000";
case "NT": return "UTC-1100";
case "IDLW": return "UTC-1200";
}
return "UTC+0000";
}
/**
* Determines the hours value in the range 1 - 12 for the AM/PM time format.
*
* @param value the input Date value
* @return the calculated hours value
*/
public static function getHoursIn12HourFormat(value:Date):Number
{
var hours:Number = value.getHours();
if(hours == 0)
{
return 12;
}
if(hours > 0 && hours <= 12)
{
return hours;
}
return hours - 12;
}
public static function getDateDifferenceByTimeUnit(minDate:Date, maxDate:Date, timeUnit:String):Number
{
var dateDifference:Number = 0;
var maxDateNumber:Number;
var minDateNumber:Number;
switch(timeUnit)
{
case TimeUnit.YEAR:
maxDateNumber = (maxDate.getFullYear() - minDate.getFullYear());
break;
case TimeUnit.MONTH:
dateDifference = (12 - minDate.getMonth()) + (maxDate.getFullYear() - minDate.getFullYear() - 1)*12 + maxDate.getMonth();
break;
case TimeUnit.DAY:
dateDifference = Math.round(Math.abs(maxDate.valueOf() - minDate.valueOf()) / (1000 * 60 * 60 * 24));
break;
case TimeUnit.HOURS:
dateDifference = Math.abs(minDate.valueOf() - maxDate.valueOf()) / (60 * 60 * 1000);
break;
case TimeUnit.MINUTES:
dateDifference = Math.abs(minDate.valueOf() - maxDate.valueOf()) / (60 * 1000);
break;
case TimeUnit.SECONDS:
dateDifference = Math.abs(minDate.valueOf() - maxDate.valueOf()) / 1000;
break;
case TimeUnit.MILLISECONDS:
dateDifference = Math.abs(minDate.valueOf() - maxDate.valueOf());
break;
}
return dateDifference;
}
}
}
+101
View File
@@ -0,0 +1,101 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.geom.Rectangle;
/**
* Utility functions for use with DisplayObjects.
*
* @author Josh Tynjala
*/
public class DisplayObjectUtil
{
/**
* Converts a point from the local coordinate system of one DisplayObject to
* the local coordinate system of another DisplayObject.
*
* @param point the point to convert
* @param firstDisplayObject the original coordinate system
* @param secondDisplayObject the new coordinate system
*/
public static function localToLocal(point:Point, firstDisplayObject:DisplayObject, secondDisplayObject:DisplayObject):Point
{
point = firstDisplayObject.localToGlobal(point);
return secondDisplayObject.globalToLocal(point);
}
/**
* Aligns a DisplayObject vertically and horizontally within specific bounds.
*
* @param target The DisplayObject to align.
* @param bounds The rectangle in which to align the target DisplayObject.
* @param horizontalAlign The alignment position along the horizontal axis. If <code>null</code>,
* the target's horizontal position will not change.
* @param verticalAlign The alignment position along the vertical axis. If <code>null</code>,
* the target's vertical position will not change.
*/
public static function align(target:DisplayObject, bounds:Rectangle, horizontalAlign:String = null, verticalAlign:String = null):void
{
var horizontalDifference:Number = bounds.width - target.width;
switch(horizontalAlign)
{
case "left":
target.x = bounds.x;
break;
case "center":
target.x = bounds.x + (horizontalDifference) / 2;
break;
case "right":
target.x = bounds.x + horizontalDifference;
break;
}
var verticalDifference:Number = bounds.height - target.height;
switch(verticalAlign)
{
case "top":
target.y = bounds.y;
break;
case "middle":
target.y = bounds.y + (verticalDifference) / 2;
break;
case "bottom":
target.y = bounds.y + verticalDifference;
break;
}
}
/**
* Resizes a DisplayObject to fit into specified bounds such that the
* aspect ratio of the target's width and height does not change.
*
* @param target The DisplayObject to resize.
* @param width The desired width for the target.
* @param height The desired height for the target.
* @param aspectRatio The desired aspect ratio. If NaN, the aspect
* ratio is calculated from the target's current
* width and height.
*/
public static function resizeAndMaintainAspectRatio(target:DisplayObject, width:Number, height:Number, aspectRatio:Number = NaN):void
{
var currentAspectRatio:Number = !isNaN(aspectRatio) ? aspectRatio : target.width / target.height;
var boundsAspectRatio:Number = width / height;
if(currentAspectRatio < boundsAspectRatio)
{
target.width = Math.floor(height * currentAspectRatio);
target.height = height;
}
else
{
target.width = width;
target.height = Math.floor(width / currentAspectRatio);
}
}
}
}
+95
View File
@@ -0,0 +1,95 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import flash.geom.Point;
import flash.display.DisplayObject;
/**
* Allows you to manipulate display objects based on a registration point other
* than the standard (0,0).
*
* @author Josh Tynjala
*/
public class DynamicRegistration
{
/**
* Moves a <code>DisplayObject</code> to a new position (x,y) based on a registration point. The
* true position of the object will be (x - registration.x, y - registration.y).
*
* @param target the DisplayObject to move
* @param registration the registration point of the DisplayObject
* @param x the new x position, in pixels
* @param y the new y position, in pixels
*/
public static function move(target:DisplayObject, registration:Point, x:Number = 0, y:Number = 0):void
{
//generate the location of the registration point in the parent
registration = target.localToGlobal(registration);
registration = target.parent.globalToLocal(registration);
//move the target and offset by the registration point
target.x += x - registration.x;
target.y += y - registration.y;
}
/**
* Rotates a <code>DisplayObject</code> based on a registration point.
*
* @param target the DisplayObject to move
* @param registration the registration point of the DisplayObject
* @param rotation the new rotation angle
*/
public static function rotate(target:DisplayObject, registration:Point, degrees:Number = 0):void
{
changePropertyOnRegistrationPoint(target, registration, "rotation", degrees);
}
/**
* Scales a <code>DisplayObject</code> based on a registration point.
*
* @param target the DisplayObject to move
* @param registration the registration point of the DisplayObject
* @param scaleX the new x scaling factor
* @param scaleY the new y scaling factor
*/
public static function scale(target:DisplayObject, registration:Point, scaleX:Number = 0, scaleY:Number = 0):void
{
changePropertyOnRegistrationPoint(target, registration, "scaleX", scaleX);
changePropertyOnRegistrationPoint(target, registration, "scaleY", scaleY);
}
/**
* @private
* Alters an arbitary property based on the registration point.
*
* @param target the DisplayObject to move
* @param registration the registration point of the DisplayObject
* @param propertyName the property to change
* @param value the new value of the property to change
*/
private static function changePropertyOnRegistrationPoint(target:DisplayObject, registration:Point, propertyName:String, value:Number):void
{
//generate the location of the registration point in the parent
var a:Point = registration.clone();
a = target.localToGlobal(a);
a = target.parent.globalToLocal(a);
target[propertyName] = value;
//after the property change, regenerate the location of the registration
//point in the parent
var b:Point = registration.clone();
b = target.localToGlobal(b);
b = target.parent.globalToLocal(b);
//move the target based on the difference to make it appear the change
//happened based on the registration point
target.x -= b.x - a.x;
target.y -= b.y - a.y;
}
}
}
+37
View File
@@ -0,0 +1,37 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
/**
* Utility functions for common geometric operations.
*
* @author Josh Tynjala
*/
public class GeomUtil
{
/**
* Converts an angle from radians to degrees.
*
* @param radians The angle in radians
* @return The angle in degrees
*/
public static function radiansToDegrees(radians:Number):Number
{
return radians * 180 / Math.PI;
}
/**
* Converts an angle from degrees to radians.
*
* @param degrees The angle in degrees
* @return The angle in radians
*/
public static function degreesToRadians(degrees:Number):Number
{
return degrees * Math.PI / 180;
}
}
}
+148
View File
@@ -0,0 +1,148 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import flash.display.Graphics;
import flash.geom.Point;
/**
* Utility functions for drawing to <code>Graphics</code> objects.
*
* @author Josh Tynjala
* @see flash.display.Graphics
*/
public class GraphicsUtil
{
/**
* @private
* Draws a wedge.
*
* @param x x component of the wedge's center point
* @param y y component of the wedge's center point
* @param startAngle starting angle in degrees
* @param arc sweep of the wedge. Negative values draw clockwise.
* @param radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
* @param yRadius [optional] y radius for wedge.
*/
public static function drawWedge(target:Graphics, x:Number, y:Number, startAngle:Number, arc:Number, radius:Number, yRadius:Number = NaN):void
{
// move to x,y position
target.moveTo(x, y);
// if yRadius is undefined, yRadius = radius
if(isNaN(yRadius))
{
yRadius = radius;
}
// limit sweep to reasonable numbers
if(Math.abs(arc) > 360)
{
arc = 360;
}
// Flash uses 8 segments per circle, to match that, we draw in a maximum
// of 45 degree segments. First we calculate how many segments are needed
// for our arc.
var segs:int = Math.ceil(Math.abs(arc) / 45);
// Now calculate the sweep of each segment.
var segAngle:Number = arc / segs;
// The math requires radians rather than degrees. To convert from degrees
// use the formula (degrees/180)*Math.PI to get radians.
var theta:Number = -(segAngle / 180) * Math.PI;
// convert angle startAngle to radians
var angle:Number = -(startAngle / 180) * Math.PI;
// draw the curve in segments no larger than 45 degrees.
if(segs > 0)
{
// draw a line from the center to the start of the curve
var ax:Number = x + Math.cos(startAngle / 180 * Math.PI) * radius;
var ay:Number = y + Math.sin(-startAngle / 180 * Math.PI) * yRadius;
target.lineTo(ax, ay);
// Loop for drawing curve segments
for(var i:int = 0; i < segs; i++)
{
angle += theta;
var angleMid:Number = angle - (theta / 2);
var bx:Number = x + Math.cos(angle) * radius;
var by:Number = y + Math.sin(angle) * yRadius;
var cx:Number = x + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
var cy:Number = y + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
target.curveTo(cx, cy, bx, by);
}
// close the wedge by drawing a line to the center
target.lineTo(x, y);
}
}
/**
* Draws a dashed line between two points.
*
* @param xStart The x position of the start of the line
* @param yStart The y position of the start of the line
* @param xEnd The x position of the end of the line
* @param yEnd The y position of the end of the line
* @param dashSize the size of dashes, in pixels
* @param gapSize the size of gaps between dashes, in pixels
*/
public static function drawDashedLine(target:Graphics, xStart:Number, yStart:Number, xEnd:Number, yEnd:Number, dashSize:Number = 10, gapSize:Number = 10):void
{
// calculate the length of a segment
var segmentLength:Number = dashSize + gapSize;
// calculate the length of the dashed line
var xDelta:Number = xEnd - xStart;
var yDelta:Number = yEnd - yStart;
var delta:Number = Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2));
// calculate the number of segments needed
var segmentCount:int = Math.floor(Math.abs(delta / segmentLength));
// get the angle of the line in radians
var radians:Number = Math.atan2(yDelta, xDelta);
// start the line here
var xCurrent:Number = xStart;
var yCurrent:Number = yStart;
// add these to cx, cy to get next seg start
xDelta = Math.cos(radians) * segmentLength;
yDelta = Math.sin(radians) * segmentLength;
// loop through each segment
for(var i:int = 0; i < segmentCount; i++)
{
target.moveTo(xCurrent, yCurrent);
target.lineTo(xCurrent + Math.cos(radians) * dashSize, yCurrent + Math.sin(radians) * dashSize);
xCurrent += xDelta;
yCurrent += yDelta;
}
// handle last segment as it is likely to be partial
target.moveTo(xCurrent, yCurrent);
delta = Math.sqrt((xEnd - xCurrent) * (xEnd - xCurrent) + (yEnd - yCurrent) * (yEnd - yCurrent));
if(delta > dashSize)
{
// segment ends in the gap, so draw a full dash
target.lineTo(xCurrent + Math.cos(radians) * dashSize, yCurrent + Math.sin(radians) * dashSize);
}
else if(delta > 0)
{
// segment is shorter than dash so only draw what is needed
target.lineTo(xCurrent + Math.cos(radians) * delta, yCurrent + Math.sin(radians) * delta);
}
// move the pen to the end position
target.moveTo(xEnd, yEnd);
}
}
}
+5
View File
@@ -0,0 +1,5 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils {␍␍ /**␍ * Methods expected to be defined by <code>ValueParser</code> and <code>FlValueParser</code>␍ * ␍ * @see com.yahoo.astra.utils.ValueParser␍ * @see com.yahoo.astra.fl.utils.FlValueParser␍ * @author kayoh␍ */␍ public interface IValueParser {␍ /**␍ * Set source and property to collect data.␍ * ␍ * @return Function Return <code>getValue</code> function.␍ * ␍ * @param source Object contained data.␍ * @param property Property of the source object.␍ */␍␍ function setValue(source : Object = null, property : Object = null) : Function ;␍␍ /**␍ * Return actual value set from <code>setValue</code>.␍ * @return Object Data collected from <code>source</code>␍ */␍ function getValue() : Object ;␍ }␍}␍
+161
View File
@@ -0,0 +1,161 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import flash.utils.getQualifiedClassName;
/**
* Creates an instance of the specified class. Sets initial properties, and calls specified methods.
*
* @author Josh Tynjala
*/
public class InstanceFactory
{
//--------------------------------------
// Constructor
//--------------------------------------
/**
* Constructor.
*/
public function InstanceFactory(targetClass:Class, properties:Object = null, methods:Object = null)
{
this.targetClass = targetClass;
this.properties = properties;
this.methods = methods;
}
//--------------------------------------
// Properties
//--------------------------------------
/**
* @private
* Storage for the targetClass property.
*/
private var _targetClass:Class = Object;
/**
* The class that will be instantiated.
*/
public function get targetClass():Class
{
return this._targetClass;
}
/**
* @private
*/
public function set targetClass(value:Class):void
{
this._targetClass = value;
}
/**
* Storage for the properties property.
*/
private var _properties:Object;
/**
* The initial values to pass to the properties of the
* newly-instantiated object.
*/
public function get properties():Object
{
return this._properties;
}
/**
* @private
*/
public function set properties(value:Object):void
{
this._properties = value;
}
/**
* @private
* Storage for the methods property.
*/
private var _methods:Object;
/**
* A set of methods to call once the object has been created and
* properties have been initialized. Format is a set of key-value pairs
* where the key is the name of the method and the value is an Array
* of parameter values.
*
* <p>Example: <code>{ load: [ "image.gif" ] }</code></p>
*/
public function get methods():Object
{
return this._methods;
}
/**
* @private
*/
public function set methods(value:Object):void
{
this._methods = value;
}
//--------------------------------------
// Public Methods
//--------------------------------------
/**
* Creates a new instance of the target class and initializes it.
*/
public function createInstance():Object
{
var instance:Object = new targetClass();
this.restoreInstance(instance);
return instance;
}
/**
* Initializes an object with the properties and methods. The object
* must be an instance of the <code>targetClass</code> property, or
* this method will throw an <code>ArgumentError</code>.
*/
public function restoreInstance(instance:Object):void
{
if(!(instance is targetClass))
{
throw new ArgumentError("Value to be initialized must be an instance of " + getQualifiedClassName(this.targetClass));
}
//set initial properties
if(this.properties)
{
for(var propName:String in this.properties)
{
if(instance.hasOwnProperty(propName))
{
instance[propName] = properties[propName];
}
}
}
//make initial method calls
//use case: Loader.load()
if(this.methods)
{
for(var methodName:String in this.methods)
{
if(instance[methodName] is Function)
{
var args:Array = this.methods[methodName] as Array;
instance[methodName].apply(instance, args);
}
}
}
}
}
}
+18
View File
@@ -0,0 +1,18 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils {␍ import mx.validators.CreditCardValidator;␍ import mx.validators.CurrencyValidator;␍ import mx.validators.DateValidator;␍ import mx.validators.EmailValidator;␍ import mx.validators.NumberValidator;␍ import mx.validators.PhoneNumberValidator;␍ import mx.validators.StringValidator;␍ import mx.validators.Validator;␍ import mx.validators.ZipCodeValidator;␍ import mx.validators.ZipCodeValidatorDomainType;
␍ /**␍ * A helper class to be used associated with <code>MX.validators</code> classes.␍ * <code>MX.validators</code> provides a variety of validation types and detailed error messages.␍ * You can edit the default error types and messages as needed.␍ * However, the use of the MXvalidator will increase your overall file size by approximately 20K.␍ * ␍ * Currently credit card, regExp and social security validations are not providing, but can be added as needed.␍ * ␍ * @example The following code shows a use of <code>MXValidationHelper</code>:␍ * <listing version="3.0">␍ * import com.yahoo.astra.utils.MXValidationHelper; ␍ * ␍ * myForm.formDataManager = new FormDataManager(FlValueParser); ; ␍ * var validator : MXValidationHelper = new MXValidationHelper(); ␍ * formDataManager.dataSource = [␍ * {id:"firstname", source:this["firstNameInput"], validator:validator.validateString, validatorExtraParam:[null, ["tooShortError","Hmmm, please enter your name."]],required:true, eventTargetObj:this["fistName_result"]},␍ * {id:"zipcode", source:this["zipcodeInput"], validator:validator.validateZipCode,required:true, eventTargetObj:this["zip_result"]},␍ * {id:"email", source:this["emailInput"], validator:validator.validateEmail,required:true },␍ * {id:"delivery", source:this["deliveryInput"], validator:validator.validateNumber, validatorExtraParam:[null, ["minValue",1], ["maxValue",20]], required:true },␍ * {id:"message", source:this["messageInput"], validator:validator.validateString, required:true },␍ * ];␍ * </listing>␍ * ␍ * @see com.yahoo.astra.managers.FormDataManager␍ * @see http://livedocs.adobe.com/flex/3/langref/mx/validators/Validator.html␍ * ␍ * @author kayoh␍ */␍ public class MXValidationHelper extends Object {
/**␍ * Validate email value. Returning an array of error messages or empty array if there is no error.␍ * ␍ * @param str String to validate. ␍ * @param baseField String Text representation of the subfield specified in the value parameter.␍ * @param args Array parameter array of <code>validator</code>'s property.␍ */␍ public function validateEmail(value : Object, baseField : String = null , ...args) : Array {␍ var emailValidator : EmailValidator = new EmailValidator();␍ emailValidator.invalidCharError = "The email address contains invalid input." ;␍ emailValidator.invalidDomainError = "The server domain in your email address has an invalid format." ;␍ emailValidator.invalidIPDomainError = "The email address contains an IP domain with an invalid format." ;␍ emailValidator.invalidPeriodsInDomainError = "There are too many periods in the domain name in your email address." ;␍ emailValidator.missingAtSignError = "Your email address is missing an 'at' sign. " ;␍ emailValidator.missingPeriodInDomainError = "The server domain in the email address is missing a period." ;␍ emailValidator.missingUsernameError = "There are no characters before the 'at' sign in your email address." ;␍ emailValidator.tooManyAtSignsError = "Your email address contains more than one 'at' sign.";␍ ␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ emailValidator[args[i][0]] = args[i][1];␍ }␍ ␍ return EmailValidator.validateEmail(emailValidator, value, baseField);␍ }
␍ /**␍ * Validate string value. Returning an array of error messages or empty array if there is no error.␍ * ␍ * @param str String to validate. ␍ * @param baseField Text representation of the subfield␍ * specified in the value parameter.␍ * @param args Object Array to override validator method. ␍ */␍ public function validateString(value : Object, baseField : String = null , ...args) : Array {␍ var stringValidator : StringValidator = new StringValidator();␍ stringValidator.minLength = 1;␍ stringValidator.maxLength = NaN;␍ stringValidator.tooShortError = "This input must have at least " + stringValidator.minLength + " characters." ;␍ stringValidator.tooLongError = "This String is longer than the " + stringValidator.maxLength + " allowed length." ;␍ ␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ stringValidator[args[i][0]] = args[i][1];␍ }␍ ␍ return StringValidator.validateString(stringValidator, value, baseField);␍ }
␍ /**␍ * Validate zipcode value. Returning an array of error messages or empty array if there is no error.␍ * ␍ * @param str String to validate. ␍ * @param baseField Text representation of the subfield specified in the value parameter. ␍ * @param args Object Array to override validator method. ␍ */
public function validateZipCode(value : Object, baseField : String = null , ...args) : Array {␍ var zipCodeValidator : ZipCodeValidator = new ZipCodeValidator();␍ zipCodeValidator.domain = ZipCodeValidatorDomainType.US_OR_CANADA;␍ zipCodeValidator.allowedFormatChars = "/\-. " ;␍ zipCodeValidator.wrongLengthError = "Provide the date as specified by inputFormat.";␍ zipCodeValidator.invalidCharError = "The ZIP code has an invalid input." ;␍ zipCodeValidator.invalidDomainError = "The domain parameter is incorrect. It has to be set to 'US Only' or 'US or Canada'." ;␍ zipCodeValidator.wrongCAFormatError = "The Canadian ZIP code needs to be in the form 'A0A 0A0'." ;␍ zipCodeValidator.wrongLengthError = "The ZIP code must consist either of 5 digits or 5+4 digits." ;␍ zipCodeValidator.wrongUSFormatError = "The ZIP+4 input must be in the form '12345-6789'." ;␍ ␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ zipCodeValidator[args[i][0]] = args[i][1];␍ }␍ ␍ return ZipCodeValidator.validateZipCode(zipCodeValidator, value, baseField);␍ }
␍ /**␍ * Validate number value. Returning an array of error messages or empty array if there is no error.␍ * ␍ * @param str String to validate. ␍ * @param baseField Text representation of the subfield specified in the value parameter.␍ * @param args Object Array to override validator method. ␍ */
public function validateNumber(value : Object, baseField : String = null, ...args) : Array {␍ var numberValidator : NumberValidator = new NumberValidator();␍ numberValidator.allowNegative = "true";␍ numberValidator.decimalPointCountError = "There cannot be more than one decimal separator.";␍ numberValidator.decimalSeparator = ".";␍ numberValidator.domain = "real"; ␍ numberValidator.exceedsMaxError = "The number provided exceeds maximum possible value.";␍ numberValidator.integerError = "The number needs to be an integer.";␍ numberValidator.invalidCharError = "Some of the characters in the input are invalid.";␍ numberValidator.invalidFormatCharsError = "One of the format settings is incorrect.";␍ numberValidator.lowerThanMinError = "The quantity entered is less than minimum.";␍ numberValidator.maxValue = "NaN";␍ numberValidator.minValue = "NaN";␍ numberValidator.negativeError = "The amount cannot be less than 0.";␍ numberValidator.precision = "-1";␍ numberValidator.precisionError = "The amount contains too many digits after the decimal separator.";␍ numberValidator.separationError = "The thousands separator must have exactly three digits after it.";␍ numberValidator.thousandsSeparator = ",";␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ numberValidator[args[i][0]] = args[i][1];␍ }␍ return NumberValidator.validateNumber(numberValidator, value, baseField);␍ }
␍ /**␍ * Validate currency value. Returning an array of error messages or empty array if there is no error.␍ * @param str String to validate. ␍ * @param baseField Text representation of the subfield specified in the value parameter.␍ * @param args Object Array to override validator method. ␍ */
public function validateCurrency(value : Object, baseField : String = null , ...args) : Array {␍ var currencyValidator : CurrencyValidator = new CurrencyValidator();␍ currencyValidator.alignSymbol = "left";␍ currencyValidator.allowNegative = "true";␍ currencyValidator.currencySymbol = "$";␍ currencyValidator.currencySymbolError = "The currency sign appears in an incorrect position.";␍ currencyValidator.decimalPointCountError = "There cannot be more than one decimal separator.";␍ currencyValidator.decimalSeparator = ".";␍ currencyValidator.exceedsMaxError = "The amount provided exceeds maximum value.";␍ currencyValidator.invalidCharError = "There are invalid characters in the input.";␍ currencyValidator.invalidFormatCharsError = "One of the format settings is incorrect.";␍ currencyValidator.lowerThanMinError = "The quantity entered is less than minimum.";␍ currencyValidator.maxValue = "NaN";␍ currencyValidator.minValue = "NaN";␍ currencyValidator.negativeError = "The amount cannot be less than 0.";␍ currencyValidator.precision = "2";␍ currencyValidator.precisionError = "The amount contains too many digits after the decimal separator.";␍ currencyValidator.separationError = "The thousands separator must have exactly three digits after it.";␍ currencyValidator.thousandsSeparator = ",";␍ ␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ currencyValidator[args[i][0]] = args[i][1];␍ }␍ ␍ return CurrencyValidator.validateCurrency(currencyValidator, value, baseField);␍ }
␍ /**␍ * Validate date value. Returning an array of error messages or empty array if there is no error.␍ * ␍ * @param str String to validate. ␍ * @param baseField Text representation of the subfield specified in the value parameter.␍ * @param args Object Array to override validator method. ␍ */
public function validateDate(value : Object, baseField : String = null , ...args) : Array {␍ var dateValidator : DateValidator = new DateValidator();␍ dateValidator.allowedFormatChars = "/\-. ";␍ dateValidator.formatError = "Configuration error: Invalid formatting string.";␍ dateValidator.inputFormat = "MM/DD/YYYY";␍ dateValidator.invalidCharError = "There are invalid characters in the date.";␍ dateValidator.validateAsString = "true";␍ dateValidator.wrongDayError = "Provide a correct day for the month.";␍ dateValidator.wrongLengthError = "Provide the date as specified by inputFormat.";␍ dateValidator.wrongMonthError = "Provide a month value between 1 and 12.";␍ dateValidator.wrongYearError = "Provide a year value between 0 and 9999.";␍ ␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ dateValidator[args[i][0]] = args[i][1];␍ }␍ ␍ return DateValidator.validateDate(dateValidator, value, baseField);␍ }
␍ /**␍ * Validate phone number value. Returning an array of error messages or empty array if there is no error.␍ * @param str String to validate. ␍ * @param baseField Text representation of the subfield specified in the value parameter.␍ * @param args Object Array to override validator method. ␍ */
public function validatePhoneNumber(value : Object, baseField : String = null , ...args) : Array {␍ var phoneNumberValidator : PhoneNumberValidator = new PhoneNumberValidator();␍ phoneNumberValidator.allowedFormatChars = "()- .+";␍ phoneNumberValidator.invalidCharError = "There are invalid characters in the phone number.";␍ phoneNumberValidator.wrongLengthError = "The phone number must consist of at least 10 digits.";␍ ␍ var argLeng : int = args.length;␍ for (var i : int = 0;i < argLeng; i++) {␍ phoneNumberValidator[args[i][0]] = args[i][1];␍ }␍ ␍ return PhoneNumberValidator.validatePhoneNumber(phoneNumberValidator, value, baseField);␍ }␍ }␍}␍
+114
View File
@@ -0,0 +1,114 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
/**
* A collection of utility functions for the manipulation of numeric values.
*
* @author Josh Tynjala
*/
public class NumberUtil
{
/**
* Rounds a Number to the nearest multiple of an input. For example, by rounding
* 16 to the nearest 10, you will receive 20. Similar to the built-in function Math.round().
*
* @param numberToRound the number to round
* @param nearest the number whose mutiple must be found
* @return the rounded number
*
* @see Math#round
*/
public static function roundToNearest(number:Number, nearest:Number = 1):Number
{
if(nearest == 0)
{
return number;
}
var roundedNumber:Number = Math.round(NumberUtil.roundToPrecision(number / nearest, 10)) * nearest;
return NumberUtil.roundToPrecision(roundedNumber, 10);
}
/**
* Rounds a Number <em>up</em> to the nearest multiple of an input. For example, by rounding
* 16 up to the nearest 10, you will receive 20. Similar to the built-in function Math.ceil().
*
* @param numberToRound the number to round up
* @param nearest the number whose mutiple must be found
* @return the rounded number
*
* @see Math#ceil
*/
public static function roundUpToNearest(number:Number, nearest:Number = 1):Number
{
if(nearest == 0)
{
return number;
}
return Math.ceil(NumberUtil.roundToPrecision(number / nearest, 10)) * nearest;
}
/**
* Rounds a Number <em>down</em> to the nearest multiple of an input. For example, by rounding
* 16 down to the nearest 10, you will receive 10. Similar to the built-in function Math.floor().
*
* @param numberToRound the number to round down
* @param nearest the number whose mutiple must be found
* @return the rounded number
*
* @see Math#floor
*/
public static function roundDownToNearest(number:Number, nearest:Number = 1):Number
{
if(nearest == 0)
{
return number;
}
return Math.floor(NumberUtil.roundToPrecision(number / nearest, 10)) * nearest;
}
/**
* Rounds a number to a certain level of precision. Useful for limiting the number of
* decimal places on a fractional number.
*
* @param number the input number to round.
* @param precision the number of decimal digits to keep
* @return the rounded number, or the original input if no rounding is needed
*
* @see Math#round
*/
public static function roundToPrecision(number:Number, precision:int = 0):Number
{
var decimalPlaces:Number = Math.pow(10, precision);
return Math.round(decimalPlaces * number) / decimalPlaces;
}
/**
* Tests equality for numbers that may have been generated by faulty floating point math.
* This is not an issue exclusive to the Flash Player, but all modern computing in general.
* The value is generally offset by an insignificant fraction, and it may be corrected.
*
* <p>Alternatively, this function could be used for other purposes than to correct floating
* point errors. Certainly, it could determine if two very large numbers are within a certain
* range of difference. This might be useful for determining "ballpark" estimates or similar
* statistical analysis that may not need complete accuracy.</p>
*
* @param number1 the first number to test
* @param number2 the second number to test
* @param precision the number of digits in the fractional portion to keep
* @return true, if the numbers are close enough to be considered equal, false if not.
*/
public static function fuzzyEquals(number1:Number, number2:Number, precision:int = 5):Boolean
{
var difference:Number = number1 - number2;
var range:Number = Math.pow(10, -precision);
//default precision checks the following:
//0.00001 < difference > -0.00001
return difference < range && difference > -range;
}
}
}
+74
View File
@@ -0,0 +1,74 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import flash.text.*;
/**
* Utility class for text fields
*
* @author Tripp Bridges
*/
public class TextUtil
{
/**
* Returns the width of a text field based on a <code>TextFormat</code> object and a string to be displayed
*
* @param textValue The text
* @param tf
*
* @return Number
*/
public static function getTextWidth(textValue:String, tf:TextFormat):Number
{
var textField:TextField = new TextField();
textField.selectable = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.text = textValue;
textField.setTextFormat(tf);
return Math.max(textField.textWidth, textField.width);
}
/**
* Returns the height of a text field based on a <code>TextFormat</code> object and a string to be displayed
*
* @param textValue The text
* @param tf
*
* @return Number
*/
public static function getTextHeight(textValue:String, tf:TextFormat):Number
{
var textField:TextField = new TextField();
textField.selectable = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.text = textValue;
textField.setTextFormat(tf);
return textField.textHeight;
}
/**
* Changes individual property of a <code>TextFormat</code> object
*/
public static function changeTextFormatProps(tf:TextFormat, tfProps:Object):TextFormat
{
for(var i:String in tfProps)
{
tf[i] = tfProps[i];
}
return tf;
}
/**
* Creates a copy of a <code>TextFormat</code> object
*/
public static function cloneTextFormat(tf:TextFormat):TextFormat
{
return new TextFormat(tf.font, tf.size, tf.color, tf.bold, tf.italic, tf.underline, tf.url, tf.target, tf.align, tf.leftMargin, tf.rightMargin, tf.indent, tf.leading);
}
}
}
+49
View File
@@ -0,0 +1,49 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
/**
* A collection of constants for date and time units.
*
* @author Josh Tynjala
*/
public class TimeUnit
{
/**
* A constant representing the year unit in date and time values.
*/
public static const YEAR:String = "year";
/**
* A constant representing the month unit in date and time values.
*/
public static const MONTH:String = "month";
/**
* A constant representing the day unit in date and time values.
*/
public static const DAY:String = "day";
/**
* A constant representing the hours unit in date and time values.
*/
public static const HOURS:String = "hours";
/**
* A constant representing the minutes unit in date and time values.
*/
public static const MINUTES:String = "minutes";
/**
* A constant representing the seconds unit in date and time values.
*/
public static const SECONDS:String = "seconds";
/**
* A constant representing the milliseconds unit in date and time values.
*/
public static const MILLISECONDS:String = "milliseconds";
}
}
+6
View File
@@ -0,0 +1,6 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils {␍ import com.yahoo.astra.utils.IValueParser;␍␍ import flash.text.TextField;
␍ /**␍ * ValueParser is a helper class that provides easy data collection from an object. It stores the <code>source</code> object and <code>property</code> to be collected, and return the actual value of it.␍ * <code>ValueParser</code> stores <code>source</code> and <code>property</code> of target data object, ␍ * and calling the function(<code>setValue</code>) when the target object is ready to be collected data.␍ * ␍ * @example The following code shows a use of <code>ValueParser</code> and <code>FlValueParser</code>:␍ * <listing version="3.0">␍ * import com.yahoo.astra.utils.ValueParser;␍ * import com.yahoo.astra.fl.utils.FlValueParser;␍ * import fl.controls.ComboBox;␍ * import fl.controls.Button;␍ * import fl.controls.TextInput;␍ * import fl.data.DataProvider;␍ * ␍ * var addressLine1:TextInput = new TextInput();␍ * var addressLine2:TextInput = new TextInput();␍ * addressLine1.text = "701 First Ave";␍ * addressLine2.text = "Sunnyvale";␍ * addressLine2.y = 25;␍ * this.addChild(addressLine1);␍ * this.addChild(addressLine2);␍ * ␍ * var myComboBox:ComboBox = statesComboBox();␍ * myComboBox.y = 50;␍ * this.addChild(myComboBox);␍ * ␍ * var submitButton:Button = new Button();␍ * submitButton.label ="Submit";␍ * submitButton.y = 75;␍ * submitButton.addEventListener(MouseEvent.CLICK, clickHandler);␍ * this.addChild(submitButton);␍ * ␍ * var myValueObect:Object = {myProperty: "State"};␍ * var myObjectValue:Function = new ValueParser().setValue(myValueObect, "myProperty");␍ * var myComboBoxValue:Function = new FlValueParser().setValue(myComboBox, "abbreviation");␍ * var myAddressInputs:Function = new FlValueParser().setValue([addressLine1,"\n",addressLine2]);␍ * ␍ * function clickHandler(e:MouseEvent):void {␍ * trace(myObjectValue()+":"+myComboBoxValue())␍ * trace(myAddressInputs());␍ * // State:CA␍ * // 701 First Ave␍ * // Sunnyvale␍ * }␍ * function statesComboBox():ComboBox {␍ * var items : XML =&lt;items&rt;␍ * &lt;item label="California" abbreviation="CA" / &gt;␍ * &lt;item label="Tennessee" abbreviation="TN" / &gt;␍ * &lt;item label="New York" abbreviation="NY" / &gt;␍ * &lt;/items&gt;␍ * var comboBox : ComboBox = new ComboBox();␍ * comboBox.dataProvider = new DataProvider(items);␍ * return comboBox;␍ * }␍ *␍ * </listing>␍ * @see com.yahoo.astra.managers.FormDataManager␍ * @see com.yahoo.astra.fl.utils.FlValueParser␍ * @author kayoh␍ */␍ public class ValueParser implements IValueParser {␍␍ protected var source : Object = null;␍ protected var property : Object = null;␍␍ /**␍ * Sets <code>source</code> and <code>property</code> of data. Returns <code>getValue</code> function as object.␍ * See the use of <code>ValueParser</code> in <code>FormDataManager</code>.␍ * ␍ * @return Function <code>getValue</code> function.␍ * ␍ * @param source Object contained data.␍ * @param property Property of the source object. If <code>source<code> is TextField, <code>property</code> will be set as "text" be default.␍ */␍ public function setValue(source : Object = null, property : Object = null) : Function {␍ this.source = source;␍ this.property = property;␍ ␍ return getValue;␍ }␍␍ /**␍ * Returns actual value set from <code>setValue</code>. ␍ * ␍ * @return Object Data collected out of <code>source</code>␍ */␍ public function getValue() : Object {␍ if(!this.source) return null;␍ // if the source is Array, will return the result as a string.␍ if(this.source is Array) {␍ var curReturnedStr : Object = "";␍ var sourceLength : int = source.length;␍ for (var i : int = 0;i < sourceLength; i++) {␍ var curSource : Object = this.source[i];␍ var curProperty : Object = (this.property) ? ((this.property is Array) ? this.property[i] : this.property ) : null;␍ var result : Object = objectValue(curSource, curProperty);␍ curReturnedStr += (result) ? result.toString() : "";␍ }␍ return curReturnedStr;␍ }␍ ␍ return objectValue(this.source, this.property);␍ ␍ return this.source;␍ }␍␍ /**␍ * @private␍ * ␍ * If source is TextField, property will be set as "text".␍ */␍ private function objectValue(source : Object = null, property : Object = null) : Object {␍ var returnedvalue : Object = source;␍ ␍ if(source is TextField) {␍ var textInput : TextField = source as TextField;␍ if(!property) property = "text";␍ returnedvalue = textInput[property];␍ } else {␍ if(source && property) returnedvalue = source[property];␍ }␍ return returnedvalue;␍ }␍ }␍}␍