CoreData

Provides facilities for data checking and conversion for all types of Flash data types.  This includes more complex data operations such as string replacement, time, and currency management.

__/ REQUIREMENTS \__

ActionScript 3.0 (or later)

__/ IMPORTS \__

flash.utils.* flash.display.DisplayObjectContainer com.bnm.api.instances.ErrorBroadcast com.bnm.api.instances.TimeObject com.bnm.api.instances.Exception

__/ EXTENDS \__

com.bnm.api.CoreObject

__/ IMPLEMENTS \__

nothing

__/ NOTICE \__

©opyright 2008 Bay New Media.  All rights, as stipulated in the The MIT License, are reserved.

This ActionScript library is licensed and released under the MIT License (http://www.opensource.org/licenses/mit-license.php).  Please refer to the accompanying text file “license.txt”, which should be distributed with every package and version of this library, for information on usage, distribution, copying, and other important information.

Please visit http://www.baynewmedia.com/ or email con.nosp@m.tact@baynewm.nosp@m.edia.com for information, questions, concerns, or bug reports.

__/ NOTES \__

This class is commented using the NaturalDocs documentation system.  It is intended to be easily read both from the direct source code and from an adaptation that is generated as hyperlinked HTML.  The NaturalDocs specification used in this class’ documentation is version 1.35 though older versions may probably be used safely.  For more information, please visit: http://www.naturaldocs.org/

The BNMAPI is officially available (primary sources) on Source Forge (http://sourceforge.net/projects/bnmapi/), on the Bay New Media site (http;//www.baynewmedia.com/), on the PeaBee project site (http://www.peabee.com/), and through the Bay New Media SVM repository server (visit http://www.baynewmedia.com/ for more information).  Downloads from other sources may not be complete or up-to-date.

If you’re interested in joining the BNMAPI project in any capacity (development, testing, distribution, etc.), please visit us on Source Forge or the Bay New Media web site.

Summary
CoreDataProvides facilities for data checking and conversion for all types of Flash data types.
Functions
CoreDataConstructor method for the class.
valueExistsChecks whether or not the value in the parameter exists.
newTimeObjectReturns an instance of a new TimeObject.
newErrorBroadcastReturns an instance of a new ErrorBroadcast object.
replaceStringReplaces a source string (the meta string) in a given input sring with a new string.
urlDecodeDecodes URL-encoded entities in the inut string to their actual values.
toHexStringConverts the input string to its hexadecimal representation.
toHexValueConverts the input number to its hexadecimal string representation.
fromHexValueConverts the input number from its hexadecimal string representation to a number value.
fromHexStringConverts the hexadecinal input string to its plain text value.
toBinaryStringConverts the input number to its binary representation as a string.
getBitReturns the bit value at the specific position within the input number.
setBitSets the bit at the specified position in the input number to the specified value.
toDollarStringConverts an input number (integer or real) into a properly formatted dollar string in the format “$##.##” (more or less numbers are used for the dollar value depending on the size of the number).
fromDollarStringConverts a string from a dollar string (such as one that would be created by the toDollarString method) and creates a number out of it.
stripLeadingSpaceStrips the leading spaces from a string and returns the processed string.
stripTrailingSpaceStrips the trailing spaces from a string and returns the processed string.
stripOutsideSpaceStrips spaces from both the end and the beginning of the input string.
splitVersionInfoSplits a version string such as “2.1.5r12” to its constituent parts.

Functions

CoreData

public function CoreData()

Constructor method for the class.

Parameters

none

Returns

CoreData: An instance of the CoreData class.

Broadcasts

nothing

Throws

nothing

Bubbles

no

valueExists

public function valueExists(... value):Boolean

Checks whether or not the value in the parameter exists.  If the parameter is an object type, it must be non-NULL and non-UNDEFINED for this method to return TRUE.  If the object is a String, it must also not be an empty string.  For numeric values, the parameter must be a number (or not NaN).  If the value is of type Array, length must be longer than 0.  For all other objects (generic or otherwise), a member variable or method of some sort must be detected, otherwise it is assumed to be empty.  In summary, the object or reference must exist and must have some value.

Parameters

value (untyped, optional): Any object or reference.

Returns

Boolean: TRUE if the parameter supplied is not NULL, UNDEFINED, a blank string if a String, and a proper number if a Number (or int/uint).  Arrays must have a length greater than 0, and objects of all other kinds must have one or more member vazriables or methods.  Otherwise, FALSE is returned.

Broadcasts

nothing

Throws

nothing

Bubbles

no

newTimeObject

public function newTimeObject(... args):TimeObject

Returns an instance of a new TimeObject.  This method is provided for easy access only, no translation is done.

Parameters

... args (untyped, optional): Any arguments that may be supplied to the TimeObject constructor.

Returns

TimeObject: An new instance of the TimeObject class.

Broadcasts

nothing

Throws

nothing

Bubbles

no

newErrorBroadcast

public function newErrorBroadcast(... args):ErrorBroadcast

Returns an instance of a new ErrorBroadcast object.  This method is provided for easy access only, no translation is done.

Parameters

... args (untyped, optional): Any arguments that may be supplied to the ErrorBroadcast constructor.

Returns

ErrorBroadcast: An new instance of the ErrorBroadcast class.

Broadcasts

nothing

Throws

nothing

Bubbles

no

replaceString

public function replaceString(sourceString: *,
targetString: *,
metaString: *):String

Replaces a source string (the meta string) in a given input sring with a new string.  For example, in the string ‘Replace %this item’ and using the string ‘%this’ as a meta string and ‘that’ as the target string, the returned value will be ‘Replace that item’.  Note that the meta string does not need to be preceeded by a percent sign (or any specific escape sequence for that matter).  It can be any string.

Parameters

sourceString (untyped, required): The input string containing one or more instances of the meta string to replace.  If this value is not a string, a conversion will be attempted. targetString (untyped, required): The string that will replace the meta string instances in the output.  If this value is not a string, a conversion will be attempted. metaString (untyped, required): The string that will be replaced with the target string in the output.  If this value is not a string, a conversion will be attempted.

Returns

String: A copy of sourceString with every instance of the meta string replaced with the target string.

Broadcasts

nothing

Throws

nothing

Bubbles

no

urlDecode

public function urlDecode(inString: String):String

Decodes URL-encoded entities in the inut string to their actual values.  This supports both standard escape sequences using numeric values (Flash <unescape> function) as well as non standard macro representations such as ‘&quot;’.  NOT ALL entities are supported but most often-used ones are.

Parameters

inString (string, required): The URL-encoded string to decode.

Returns

string: The string in standard ISO-8859 text format.

Broadcasts

nothing

Throws

nothing

Bubbles

no

toHexString

public function toHexString(input: String):String

Converts the input string to its hexadecimal representation.  Each byte’s decinal value is converted to its hexadecimal value and the two-digit string is appended to the output.  Values less than 10 have a 0 prepended to ensure correct re-translation (i.e.  A = 0A).  The input string “Hello” would become decimal 72+101+108+108+111 and hex 48+65+6C+6C+6F which is lumped together into the output string “48656C6C6F”.  Due to this transformation, the output string will always be exactly twice the size of the input string.

Parameters

input (string, required): The string to convert to its hexadecimal representation.

Output

String: The hexadecimal representation of the input string, or UNDEFINED if there was a problem during conversion.

Broadcasts

nothing

Throws

nothing

See also

fromHexString

toHexValue

public function toHexValue(input: Number):String

Converts the input number to its hexadecimal string representation.  Because numbers in Flash are always 32 bits long, the output value will always be 8 hexadecimal characters long.  This is very similar to the “0x######” format except that it contains an extra byte of information.

Parameters

input (number, required): The number to convert to its hexadecimal string representation.

Output

String: The hexadecimal representation of the input number, or UNDEFINED if there was a problem during conversion.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

fromHexValue

fromHexValue

public function fromHexValue(input: String):Number

Converts the input number from its hexadecimal string representation to a number value.  Because numbers in Flash are always 32 bits long, the input string must always be 8 characters long.

Parameters

input (string, required): The number to convert to its hexadecimal value representation.

Output

Number: The numeric value represented by the input string.  Undefined if the input value was not supplied.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

toHexValue

fromHexString

public function fromHexString(input: String):String

Converts the hexadecinal input string to its plain text value.  This essentially reverses the operation of the toHexString method.

Parameters

input (string, required): The string to convert to its plain text value.

Output

String: The plain text value of the hexadecimal input string, or UNDEFINED if there was a problem during conversion.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

toHexString

toBinaryString

public function toBinaryString (inputNum: *):String

Converts the input number to its binary representation as a string.  Because all numbers are treated as 32-bit values in Flash, this will always result in a 32 character output string.

Parameters

inputNum (Number, int, or uint, required): The string to convert to a 32-bit binary string sequence.

Returns

String: The 32 character representation of the input parameter’s binary value, or NULL if the inpur parameter was not a valid numeric type.

Broadcasts

nothing

Throws

nothing

Bubbles

no

getBit

public function getBit(bitPos: Number,
inputNum: Number):Boolean

Returns the bit value at the specific position within the input number.  The offset is 1-based so that 1 is the lowest position and 32 is the highest position.

Parameters

bitPos (Number, required): The bit position to retrieve within the inputNum parameter. inputNum (Number, required): The number from which to extract the bit value.  Always a 32-bit value.

Returns

Boolean: TRUE or FALSE depending on the bit value requested.  This may be translated to 1 or 0 respectively.  If the input parameters are out of range or not correctly typed, UNDEFINED is returned.

Broadcasts

nothing

Throws

nothing

Bubbles

no

setBit

public function setBit(bitPos: Number,
inputNum: Number,
bitVal: Boolean)

Sets the bit at the specified position in the input number to the specified value.

Parameters

bitPos (Number, required): The bit position to operate on within the inputNum parameter.  This is 1 based so that a value of 1 refers to the first bit. inputNum (Number, required): The number within which to manipulate the bit value. bitVal (Boolean, required): The value to set the specifed bit to.  TRUE or FALSE is translated to 1 and 0 respectively.

Returns

Number: The input value with the specified bit manipulated to the specified value.

Broadcasts

nothing

Throws

nothing

Bubbles

no

toDollarString

public function toDollarString (inp: Number,
dollarSign: String):String

Converts an input number (integer or real) into a properly formatted dollar string in the format “$##.##” (more or less numbers are used for the dollar value depending on the size of the number).

Parameters

inp (number, required): The integer (whole) or real (decimal) number to convert into a dollar string. dollarSign (string, optional): The symbol to prepend to the string.  Be default (if not supplied), this value is “$”.

Returns

string: The dollar value of the inp value in a properly formatted dollar format.  A null string is returned if the inp parameter is not numeric or cannot be converted to a number.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

fromDollarString

fromDollarString

public function fromDollarString (inp: String):*

Converts a string from a dollar string (such as one that would be created by the toDollarString method) and creates a number out of it.  This is done by stripping out all non-numeric values with the exception of a period (if present).  If more than one period is found, only the first period from the left is used to denote a decimal separator and remaining periods are stripped out.

Parameters

inp (string, required): The dollar-formatted string to convert to a number value.

Returns

number: The numeric representation of the dollar string.  A NULL value is returned if the `inp` paramater is not and cannot be converted into a string.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

toDollarString

stripLeadingSpace

public function stripLeadingSpace(inputStr: String):String

Strips the leading spaces from a string and returns the processed string.

Parameters

inputStr (string, required): The string from which to strip the leading spaces.  This string won’t itself be affected.

Returns

String: The inputStr string with all leading spaces stripped.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

stripTrailingSpace

stripTrailingSpace

public function stripTrailingSpace(inputStr: String):String

Strips the trailing spaces from a string and returns the processed string.

Parameters

inputStr (string, required): The string from which to strip the trailing spaces.  This string won’t itself be affected.

Returns

String: The inputStr string with all trailling spaces stripped.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

stripLeadingSpace

stripOutsideSpace

public function stripOutsideSpace (inputStr: String):String

Strips spaces from both the end and the beginning of the input string.  This produces the same result as calling stripTrailingSpace and stripLeadingSpace on a string.

Parameters

inputStr (string, required): The string from which to strip the leading and trailing spaces.  T this string won’t be affected.

Returns

String: The inputStr string with all leading and trailling spaces stripped.

Broadcasts

nothing

Throws

nothing

Bubbles

no

See also

stripLeadingSpace stripTrailingSpace

splitVersionInfo

public function splitVersionInfo(versionString: String):Object

Splits a version string such as “2.1.5r12” to its constituent parts.  Any values not specified in the parameter string are returned as NULL values otherwise they’re returned as int types.  The format for the string is: “major.minor.sub R revision”.

Parameters

versionString (string, required): The string to split up into version information pieces.

Returns

Object: An object containing version information, in pieces, as numeric int types.  This includes the values: major (int): The major version number (first number in the dot series). minor (int): The number after the first period in the series.  May be NULL if not specified. sub (int): The number after the second period in the series.  May be NULL if not specified. revision (int): Any number after an “r” or “R” designator in the version series, or NULL if not specified.

Broadcasts

nothing

Throws

nothing

Bubbles

no

The CoreObject class is the top of the API trunk chain.
Stores dates, both absolute and relative, and calculates differences.
Used for reporting and broadcasting errors.
Used for reporting fatal errors that occur in an application.
The Introspection class is used to analyze, or “introspect”, a running application.
public function CoreData()
Constructor method for the class.
public function valueExists(... value):Boolean
Checks whether or not the value in the parameter exists.
public function newTimeObject(... args):TimeObject
Returns an instance of a new TimeObject.
public function newErrorBroadcast(... args):ErrorBroadcast
Returns an instance of a new ErrorBroadcast object.
public function replaceString(sourceString: *,
targetString: *,
metaString: *):String
Replaces a source string (the meta string) in a given input sring with a new string.
public function urlDecode(inString: String):String
Decodes URL-encoded entities in the inut string to their actual values.
public function toHexString(input: String):String
Converts the input string to its hexadecimal representation.
public function toHexValue(input: Number):String
Converts the input number to its hexadecimal string representation.
public function fromHexValue(input: String):Number
Converts the input number from its hexadecimal string representation to a number value.
public function fromHexString(input: String):String
Converts the hexadecinal input string to its plain text value.
public function toBinaryString (inputNum: *):String
Converts the input number to its binary representation as a string.
public function getBit(bitPos: Number,
inputNum: Number):Boolean
Returns the bit value at the specific position within the input number.
public function setBit(bitPos: Number,
inputNum: Number,
bitVal: Boolean)
Sets the bit at the specified position in the input number to the specified value.
public function toDollarString (inp: Number,
dollarSign: String):String
Converts an input number (integer or real) into a properly formatted dollar string in the format “$##.##” (more or less numbers are used for the dollar value depending on the size of the number).
public function fromDollarString (inp: String):*
Converts a string from a dollar string (such as one that would be created by the toDollarString method) and creates a number out of it.
public function stripLeadingSpace(inputStr: String):String
Strips the leading spaces from a string and returns the processed string.
public function stripTrailingSpace(inputStr: String):String
Strips the trailing spaces from a string and returns the processed string.
public function stripOutsideSpace (inputStr: String):String
Strips spaces from both the end and the beginning of the input string.
public function splitVersionInfo(versionString: String):Object
Splits a version string such as “2.1.5r12” to its constituent parts.
Stores and automatically calculates time values for hours, minutes, seconds, and milliseconds.