|
A Simple Helper Class called Checker
/* This class is used in the simple flv player to check the property values of xml */
package classes
{
/* The word "classes" at the end of this package declaration means that
this file is in a folder named classes.
The name of the file would be Checker.as, in the simple flv example it will get imported in. */
public class Checker
{
private var theObject:*;
private var numz:String = "-0123456789";
private var alphaz:String = "abcdefghijklmnopqrstuvwxyz";
private var nocs:String = ")(*&^%$#@!~`:;-'\"?><{}+_[]/|,\.";
public function Checker(theObjectToCheck:*):void
{
theObject = theObjectToCheck;
}
public function property(thisProperty:String, defaultValue:* = null, resultShouldBe:String = null):*
{
var outPut:* = defaultValue;
if (theObject) {
if (theObject.hasOwnProperty(thisProperty)) {
if (resultShouldBe == "justNumbers") {
outPut = ancheck(theObject[thisProperty], defaultValue, "n");
}
if (resultShouldBe == "justAlphas") {
outPut = ancheck(theObject[thisProperty], defaultValue);
}
if (resultShouldBe == null) {
outPut = theObject[thisProperty];
}
}
}
return outPut;
}
private function ancheck(onthis:*, toreturner:*, aorn:String = "a"):*
{
var inq:String = onthis.toString();
if (aorn == "a")
{
var alphacheck:int = 0;
for (var i:int = 0; i<inq.length; i++)
{
if (numz.indexOf(inq.charAt(i)) != -1)
{alphacheck = 0;}
if (nocs.indexOf(inq.charAt(i)) != -1)
{alphacheck = 0;}
if (alphaz.indexOf(inq.charAt(i).toLowerCase()) != -1)
{++alphacheck;}
}
if (alphacheck == inq.length)
{toreturner = onthis;}
}
else
{
var numon:String = onthis.toString();
if (numon.indexOf(".") != -1)
{numon = numon.replace(/\./g, "");}
var numcheck:int = 0;
for (var j:int = 0; j<numon.length; j++)
{
if (alphaz.indexOf(numon.charAt(j).toLowerCase()) != -1)
{numcheck = 0;}
if (nocs.indexOf(numon.charAt(j)) != -1)
{numcheck = 0;}
if (numz.indexOf(numon.charAt(j)) != -1)
{++numcheck;}
}
if (numcheck == numon.length)
{toreturner = onthis;}
}
return toreturner;
}
public function has(thiser:String):Boolean
{
var outB:Boolean = false;
if (theObject && theObject.hasOwnProperty(thiser)) {outB = true;}
return outB;
}
}
}
|