├── .gitignore
├── Contribution Guidelines.md
├── Libraries to integrate.md
├── NOTES.md
├── README.md
├── TODO.md
├── bin
└── as3-utils.swc
├── build.properties
├── build.xml
├── build
├── flexunit
│ └── flexUnitTasks-4.1.0-33.jar
└── pmd
│ ├── LICENSE.txt
│ ├── as3-parser-1.1.jar
│ ├── as3-parser-api-1.1.jar
│ ├── as3-plugin-utils-1.1.jar
│ ├── commons-lang-2.4.jar
│ ├── dom4j-1.6.1.jar
│ ├── flex-pmd-ant-task-1.1.jar
│ ├── flex-pmd-command-line-1.1.jar
│ ├── flex-pmd-command-line-api-1.1.jar
│ ├── flex-pmd-core-1.1.jar
│ ├── flex-pmd-cpd-1.1.jar
│ ├── flex-pmd-cpd-ant-task-1.1.jar
│ ├── flex-pmd-cpd-command-line-1.1.jar
│ ├── flex-pmd-files-1.1.jar
│ ├── flex-pmd-metrics-1.1.jar
│ ├── flex-pmd-metrics-ant-task-1.1.jar
│ ├── flex-pmd-metrics-command-line-1.1.jar
│ ├── flex-pmd-ruleset-1.1.jar
│ ├── flex-pmd-ruleset-api-1.1.jar
│ ├── jsap-2.1.jar
│ ├── plexus-utils-1.0.2.jar
│ └── pmd-4.2.5.jar
├── libs
├── flexunit-4.1.0-33-as3_3.5.0.12683.swc
├── flexunit-cilistener-4.1.0-33-3.5.0.12683.swc
├── flexunit-uilistener-4.1.0-33-3.5.0.12683.swc
├── hamcrest-as3-flex-1.1.3.swc
└── mockolate-0.9.3.swc
├── res
└── flex-formatter.properties
├── src
├── .gitignore
├── deprecated
│ ├── .gitignore
│ ├── confine.as
│ ├── constrain.as
│ ├── getURL.as
│ ├── randomBoolean.as
│ ├── randomRangeFloat.as
│ └── randomRangeInt.as
└── utils
│ ├── align
│ ├── alignCenter.as
│ ├── alignLeft.as
│ ├── alignRight.as
│ ├── alignToRectangleBottom.as
│ ├── alignToRectangleCenter.as
│ ├── alignToRectangleCenterMiddle.as
│ ├── alignToRectangleLeft.as
│ ├── alignToRectangleMiddle.as
│ ├── alignToRectangleRight.as
│ ├── alignToRectangleTop.as
│ ├── getPositionToTheRightOf.as
│ ├── getPositionUnder.as
│ ├── gridAlignSpaceNumber.as
│ ├── gridAlignSpaceNumberGap.as
│ ├── horizontalAlign.as
│ ├── horizontalAlignNoSpace.as
│ ├── horizontalAlignSpaceArray.as
│ ├── horizontalAlignSpaceNumber.as
│ ├── interpolate.as
│ ├── interpolateMultiX.as
│ ├── interpolateMultiY.as
│ ├── interpolateX.as
│ ├── interpolateY.as
│ ├── verticalAlign.as
│ ├── verticalAlignNoSpace.as
│ ├── verticalAlignSpaceArray.as
│ ├── verticalAlignSpaceNumber.as
│ ├── xAlignCenter.as
│ ├── xAlignLeft.as
│ ├── xAlignRight.as
│ ├── yAlignCenter.as
│ ├── yAlignLeft.as
│ └── yAlignRight.as
│ ├── array
│ ├── addItemsAt.as
│ ├── arrayContainsValue.as
│ ├── arraysAreEqual.as
│ ├── average.as
│ ├── contains.as
│ ├── containsAll.as
│ ├── containsAny.as
│ ├── copyArray.as
│ ├── createUniqueCopy.as
│ ├── equals.as
│ ├── getHighestValue.as
│ ├── getIndexOfDifference.as
│ ├── getItemByKey.as
│ ├── getItemByType.as
│ ├── getItemsByKey.as
│ ├── getItemsByType.as
│ ├── getLowestValue.as
│ ├── getRandomElement.as
│ ├── randomize.as
│ ├── removeDuplicates.as
│ ├── removeItem.as
│ ├── removeItems.as
│ ├── removeValueFromArray.as
│ ├── retainItems.as
│ └── sum.as
│ ├── assert
│ ├── assertArrayContains.as
│ ├── assertArrayItemsTypeOf.as
│ ├── assertDictionaryKeysTypeOf.as
│ ├── assertHasText.as
│ ├── assertInstanceOf.as
│ ├── assertIsTrue.as
│ ├── assertNotNull.as
│ └── assertState.as
│ ├── boolean
│ ├── randomBoolean.as
│ └── randomChance.as
│ ├── capabilities
│ ├── getPlayerInfo.as
│ ├── isAirApplication.as
│ ├── isIDE.as
│ ├── isMac.as
│ ├── isPC.as
│ ├── isPlugin.as
│ ├── isStandAlone.as
│ └── isWeb.as
│ ├── color
│ ├── HSLtoHSV.as
│ ├── HSLtoRGB.as
│ ├── HSVtoHSL.as
│ ├── HSVtoRGB.as
│ ├── HueToRGB.as
│ ├── RGBToHue.as
│ ├── RGBtoHSL.as
│ ├── RGBtoHSV.as
│ ├── averageBlue.as
│ ├── averageColorProperty.as
│ ├── averageGreen.as
│ ├── averageHue.as
│ ├── averageLightness.as
│ ├── averageRed.as
│ ├── averageSaturation.as
│ ├── averageValue.as
│ ├── changeContrast.as
│ ├── getARGB.as
│ ├── getColor.as
│ ├── getColorFromDisplayObject.as
│ ├── getHexStringFromARGB.as
│ ├── getHexStringFromRGB.as
│ ├── getRGB.as
│ ├── getTransform.as
│ ├── interpolateColor.as
│ ├── invertColor.as
│ ├── randomColor.as
│ ├── resetColor.as
│ ├── setARGB.as
│ ├── setColor.as
│ ├── setTransform.as
│ ├── toColor.as
│ ├── toGrayscale.as
│ ├── toHTML.as
│ ├── toHexString.as
│ └── toRGBComponents.as
│ ├── conversion
│ ├── bitsToBytes.as
│ ├── bitsToKilobits.as
│ ├── bitsToKilobytes.as
│ ├── bytesToBits.as
│ ├── bytesToKilobits.as
│ ├── bytesToKilobytes.as
│ ├── daysToHours.as
│ ├── daysToMilliseconds.as
│ ├── daysToMinutes.as
│ ├── daysToSeconds.as
│ ├── degreesToRadians.as
│ ├── hoursToDays.as
│ ├── hoursToMilliseconds.as
│ ├── hoursToMinutes.as
│ ├── hoursToSeconds.as
│ ├── kilobitsToBits.as
│ ├── kilobitsToBytes.as
│ ├── kilobitsToKilobytes.as
│ ├── kilobytesToBits.as
│ ├── kilobytesToBytes.as
│ ├── kilobytesToKilobits.as
│ ├── millisecondsToDays.as
│ ├── millisecondsToHours.as
│ ├── millisecondsToMinutes.as
│ ├── millisecondsToSeconds.as
│ ├── minutesToDays.as
│ ├── minutesToHours.as
│ ├── minutesToMilliseconds.as
│ ├── minutesToSeconds.as
│ ├── radiansToDegrees.as
│ ├── secondsToDays.as
│ ├── secondsToHours.as
│ ├── secondsToMilliseconds.as
│ └── secondsToMinutes.as
│ ├── cookie
│ ├── getCookie.as
│ └── setCookie.as
│ ├── date
│ ├── Calendar.as
│ ├── TimeRelationships.as
│ ├── Timezone.as
│ ├── addWeeks.as
│ ├── ceil.as
│ ├── clone.as
│ ├── compareDates.as
│ ├── dayAbbrNames.as
│ ├── dayNames.as
│ ├── equals.as
│ ├── floor.as
│ ├── formatDate.as
│ ├── formatWeekOf.as
│ ├── getAMPM.as
│ ├── getCountdownUntil.as
│ ├── getDayAbbrName.as
│ ├── getDayAsString.as
│ ├── getDayName.as
│ ├── getDayOfTheYear.as
│ ├── getDaysInMonth.as
│ ├── getEarliestDate.as
│ ├── getFormattedDifferenceFromUTC.as
│ ├── getInternetTime.as
│ ├── getLastMonday.as
│ ├── getLastSunday.as
│ ├── getLatestDate.as
│ ├── getMeridiem.as
│ ├── getMonthAbbrName.as
│ ├── getMonthName.as
│ ├── getNextDay.as
│ ├── getPreviousDay.as
│ ├── getShortHour.as
│ ├── getShortYear.as
│ ├── getStartOfWeek.as
│ ├── getTimeBetween.as
│ ├── getTimeElapsedString.as
│ ├── getTimezone.as
│ ├── getUTCDate.as
│ ├── getWeekOfTheYear.as
│ ├── isDaylightSavings.as
│ ├── isInCurrentWeek.as
│ ├── isLeapYear.as
│ ├── isPast.as
│ ├── iso8601ToDate.as
│ ├── makeMorning.as
│ ├── makeNight.as
│ ├── monthAbbrNames.as
│ ├── monthNames.as
│ ├── parseW3CDTF.as
│ ├── timeCode.as
│ ├── toW3CDTF.as
│ └── toggleAMPM.as
│ ├── dictionary
│ ├── CircularDictionary.as
│ ├── getKeys.as
│ └── getValues.as
│ ├── display
│ ├── Alignment.as
│ ├── IDisplayObject.as
│ ├── addChild.as
│ ├── applyNaturalScrollRect.as
│ ├── bringForward.as
│ ├── bringToFront.as
│ ├── centerWithin.as
│ ├── createBitmap.as
│ ├── createThumb.as
│ ├── cropBitmapData.as
│ ├── duplicateDisplayObject.as
│ ├── filterChildrenByProps.as
│ ├── findAncestor.as
│ ├── findAncestorWithType.as
│ ├── fitIntoRect.as
│ ├── getChildren.as
│ ├── getFullBounds.as
│ ├── getParents.as
│ ├── isVisible.as
│ ├── localToLocal.as
│ ├── moveBy.as
│ ├── moveTo.as
│ ├── originalHeight.as
│ ├── originalWidth.as
│ ├── relativePos.as
│ ├── removeAllChildren.as
│ ├── removeAllChildrenByType.as
│ ├── removeChild.as
│ ├── removeChildAt.as
│ ├── scheduleForNextFrame.as
│ ├── sendBackward.as
│ ├── sendToBack.as
│ ├── setProperties.as
│ ├── showChildren.as
│ ├── stopAllTimelines.as
│ ├── sumProps.as
│ ├── traceChildren.as
│ ├── transformToFitRect.as
│ └── wait.as
│ ├── draw
│ ├── createCircleShape.as
│ ├── createEllipseShape.as
│ ├── createRectangleShape.as
│ ├── drawRoundRect.as
│ └── drawWedge.as
│ ├── error
│ └── getStackTrace.as
│ ├── frame
│ ├── addFrameScript.as
│ ├── getFrameNumberForLabel.as
│ └── removeFrameScript.as
│ ├── fullscreen
│ └── toggleFullScreen.as
│ ├── garbageCollection
│ └── gc.as
│ ├── geom
│ ├── Direction.as
│ ├── Ellipse.as
│ ├── Point3d.as
│ ├── Side.as
│ ├── angle.as
│ ├── cartesianToPolarCoordinates.as
│ ├── getRectangleCenter.as
│ ├── getRectanglePerimeter.as
│ ├── polarToCartesianCoordinates.as
│ ├── randomPoint.as
│ ├── reverseRectangle.as
│ ├── rotatePoint.as
│ ├── roundPoint.as
│ ├── simplifyAngle.as
│ └── trimAngle.as
│ ├── html
│ ├── a.as
│ ├── br.as
│ ├── entities.as
│ ├── img.as
│ ├── p.as
│ ├── span.as
│ └── styledTag.as
│ ├── js
│ └── callJSFunction.as
│ ├── library
│ ├── getBitmapDataFromLibrary.as
│ ├── getClassFromLibrary.as
│ └── getClipFromLibrary.as
│ ├── load
│ ├── calculateBps.as
│ ├── calculateBufferPercent.as
│ ├── calculateKBps.as
│ ├── calculateMillisecondsUntilBuffered.as
│ └── checkDomain.as
│ ├── location
│ ├── getDomain.as
│ ├── getLocationName.as
│ ├── isDomain.as
│ ├── locationNames.as
│ ├── openURL.as
│ ├── openWindow.as
│ └── windowNames.as
│ ├── math
│ ├── Percent.as
│ ├── Range.as
│ ├── expressAsOdds.as
│ └── gcd.as
│ ├── mvc
│ ├── AbstractController.as
│ ├── AbstractModel.as
│ ├── AbstractView.as
│ ├── IController.as
│ ├── IModel.as
│ └── IView.as
│ ├── number
│ ├── addLeadingZeroes.as
│ ├── clamp.as
│ ├── createStepsBetween.as
│ ├── fastMax2.as
│ ├── fastMin2.as
│ ├── format.as
│ ├── getOrdinalSuffix.as
│ ├── getWeightedAverage.as
│ ├── hexChars.as
│ ├── insertCommas.as
│ ├── interpolate.as
│ ├── isBetween.as
│ ├── isEqual.as
│ ├── isEven.as
│ ├── isInteger.as
│ ├── isNegative.as
│ ├── isOdd.as
│ ├── isPositive.as
│ ├── isPrime.as
│ ├── isRoughlyEqual.as
│ ├── loopIndex.as
│ ├── map.as
│ ├── max.as
│ ├── min.as
│ ├── normalize.as
│ ├── pad.as
│ ├── randomIntegerWithinRange.as
│ ├── randomSign.as
│ ├── randomWithinRange.as
│ ├── rol.as
│ ├── ror.as
│ ├── round.as
│ ├── roundDecimalToPlace.as
│ └── toHex.as
│ ├── object
│ ├── assign.as
│ ├── clone.as
│ ├── combine.as
│ ├── contains.as
│ ├── copy.as
│ ├── create.as
│ ├── createInstance.as
│ ├── getKeys.as
│ ├── hasAnyProperties.as
│ ├── inspect.as
│ ├── isEmpty.as
│ ├── isNull.as
│ ├── isSimple.as
│ ├── isUniformPropertyType.as
│ ├── merge.as
│ ├── numProperties.as
│ ├── toArray.as
│ └── toString.as
│ ├── range
│ ├── center.as
│ ├── isInRange.as
│ ├── randomRangeDate.as
│ ├── randomRangeSet.as
│ └── resolve.as
│ ├── ratio
│ ├── defineRect.as
│ ├── heightToWidth.as
│ ├── scale.as
│ ├── scaleHeight.as
│ ├── scaleToFill.as
│ ├── scaleToFit.as
│ ├── scaleWidth.as
│ └── widthToHeight.as
│ ├── string
│ ├── addSlashes.as
│ ├── afterFirst.as
│ ├── afterLast.as
│ ├── arrayList.as
│ ├── beforeFirst.as
│ ├── beforeLast.as
│ ├── beginsWith.as
│ ├── between.as
│ ├── constants.as
│ ├── convertBytesString.as
│ ├── detectBr.as
│ ├── endsWith.as
│ ├── equals.as
│ ├── firstToUpper.as
│ ├── getLettersFromString.as
│ ├── htmlDecode.as
│ ├── htmlEncode.as
│ ├── ltrim.as
│ ├── numberToString.as
│ ├── padLeft.as
│ ├── padRight.as
│ ├── randomCharacters.as
│ ├── randomLowercaseCharacters.as
│ ├── randomNumberString.as
│ ├── randomSequence.as
│ ├── randomSpecialCharacters.as
│ ├── remove.as
│ ├── removeExtraWhitespace.as
│ ├── removeSpaces.as
│ ├── removeTabs.as
│ ├── repeat.as
│ ├── replace.as
│ ├── reverse.as
│ ├── reverseWords.as
│ ├── rtrim.as
│ ├── sanitizeNull.as
│ ├── search.as
│ ├── slashUnsafeChars.as
│ ├── stringHasValue.as
│ ├── stringsAreEqual.as
│ ├── stripSlashes.as
│ ├── stripTags.as
│ ├── toDoubleQuote.as
│ ├── toNumeric.as
│ ├── toSingleQuote.as
│ ├── toTitleCase.as
│ ├── trim.as
│ ├── trimCamel.as
│ ├── truncate.as
│ ├── truncate2.as
│ ├── wordCount.as
│ └── xtrim.as
│ ├── swf
│ └── SWFReader.as
│ ├── textField
│ ├── TextFieldWrapper.as
│ ├── clearFields.as
│ ├── createField.as
│ ├── formatFields.as
│ ├── getUsableFonts.as
│ ├── hideFields.as
│ ├── revealFields.as
│ ├── setFormattedText.as
│ ├── setStyledText.as
│ ├── setTextColor.as
│ ├── setTextFont.as
│ ├── setTextLeading.as
│ ├── setTextLetterSpacing.as
│ ├── setTextSpaceWidth.as
│ ├── styleFields.as
│ ├── truncateMultilineText.as
│ └── truncateText.as
│ ├── type
│ ├── PACKAGE_CLASS_SEPARATOR.as
│ ├── convertFullyQualifiedName.as
│ ├── describeInheritance.as
│ ├── describeMethods.as
│ ├── describeProperties.as
│ ├── describeType.as
│ ├── forInstance.as
│ ├── forName.as
│ ├── getClass.as
│ ├── getClassByName.as
│ ├── getClassName.as
│ ├── getDisplayObjectClass.as
│ ├── getFullyQualifiedName.as
│ ├── getFullyQualifiedSuperClassname.as
│ ├── getName.as
│ ├── getNameFromFullyQualifiedName.as
│ ├── getPropertyType.as
│ ├── getSuperClassName.as
│ ├── getType.as
│ ├── isInterface.as
│ ├── isPassedByValue.as
│ ├── isType.as
│ ├── newInstance.as
│ ├── registerType.as
│ ├── strictIs.as
│ └── typeCache.as
│ ├── validation
│ ├── US_STATE_ABBREVIATIONS.as
│ ├── encodeCreditCardNumber.as
│ ├── getCreditCardProvider.as
│ ├── isBlank.as
│ ├── isCreditCard.as
│ ├── isEmail.as
│ ├── isNumeric.as
│ ├── isPOBox.as
│ ├── isURL.as
│ ├── isUSAStateAbbreviation.as
│ ├── isValidCreditCardNumber.as
│ ├── isValidEmailAddress.as
│ ├── isValidExpirationDate.as
│ └── isValidPhoneNumber.as
│ └── xml
│ ├── XMLConstants.as
│ ├── getNextSibling.as
│ ├── getPreviousSibling.as
│ ├── getSiblingByIndex.as
│ └── isValidXML.as
└── test
├── UtilsTestRunner.as
├── UtilsTestSuite.as
└── utils
├── align
├── AlignLeftTest.as
├── AlignRightTest.as
└── alignCenterTest.as
├── date
├── GetNextDayTest.as
├── GetPrevDayTest.as
├── GetTimeElapsedStringTest.as
└── calendar
│ └── CalendarTests.as
├── dictionary
└── CircularDictionaryTest.as
├── display
└── FindAncestorTest.as
├── geom
├── CartesianToPolarCoordinatesTest.as
└── PolarToCartesianCoordinatesTest.as
├── number
├── ClampTest.as
└── ToHexTest.as
├── object
├── CreateInstanceTest.as
├── CreateTest.as
├── MergeTest.as
├── cloneTest.as
└── containsTest.as
├── range
└── RandomRangeDateTest.as
├── string
├── numberToStringTest.as
└── stringHasValueTest.as
├── type
├── IsPassedByValueTest.as
└── StrictIsTest.as
├── validation
├── IsValidEmailAddressTest.as
├── encodeCreditCardNumberTest.as
├── getCreditCardProviderTest.as
├── isBlankTest.as
├── isCreditCardTest.as
├── isEmailTest.as
├── isNumericTest.as
├── isPOBoxTest.as
├── isUSAStateAbbreviationTest.as
├── isUrlTest.as
├── isValidCreditCardNumberTest.as
├── isValidExpirationDateTest.as
└── isValidPhoneNumberTest.as
└── xml
├── GetNextSiblingTest.as
├── GetPreviousSiblingTest.as
├── GetSiblingByIndexTest.as
└── isValidXMLTest.as
/.gitignore:
--------------------------------------------------------------------------------
1 | src/FlexUnitApplication.mxml
2 | src/FlexUnitCompilerApplication.mxml
3 | target
4 | bin/FlexUnitApplication.swf
5 | bin-debug
6 | bin-release
7 | *.iml
8 | .actionScript*
9 | .flex*
10 | .Flex*
11 | .project
12 | .settings/
13 | .DS_Store
14 | launch
15 | org.eclipse.core.resources.prefs
--------------------------------------------------------------------------------
/Libraries to integrate.md:
--------------------------------------------------------------------------------
1 | * Sekati - [http://code.google.com/p/sekati/](http://code.google.com/p/sekati/)
2 | * BumpSlide - [http://code.google.com/p/bumpslide/](http://code.google.com/p/bumpslide/)
3 | * as3MathLib - [http://code.google.com/p/as3mathlib/](http://code.google.com/p/as3mathlib/)
4 | * casaLib - [http://casalib.org/about/](http://http://casalib.org/about/)
--------------------------------------------------------------------------------
/TODO.md:
--------------------------------------------------------------------------------
1 | # TODO
2 |
3 | - combine with [asx](http://github.com/drewbourne/asx)
4 | - attribute all functions to proper authors
5 | - check utils for duplicates
6 | - clean package structure
7 | - clean parameter names to be descriptive
8 | - code formatting
9 | - build out tests
10 | - optimize
11 | - documentation
12 | - examples
13 | - replace default FlexPMD ruleset as it is awkward.
--------------------------------------------------------------------------------
/bin/as3-utils.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/bin/as3-utils.swc
--------------------------------------------------------------------------------
/build.properties:
--------------------------------------------------------------------------------
1 | project.name=as3-utils
2 |
3 | build.groupId=as3
4 | build.artifactId=as3-utils
5 | build.version=0.1
6 | build.artifact=${build.artifactId}-${build.version}
7 |
8 | test.runner=UtilsTestRunner
9 | test.runner.ext=as
10 |
11 | flexunit.version=4.1.0-33
12 | flexsdk.version=3.5.0.12683
13 | flexpmd.version=1.1
--------------------------------------------------------------------------------
/build/flexunit/flexUnitTasks-4.1.0-33.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/flexunit/flexUnitTasks-4.1.0-33.jar
--------------------------------------------------------------------------------
/build/pmd/as3-parser-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/as3-parser-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/as3-parser-api-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/as3-parser-api-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/as3-plugin-utils-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/as3-plugin-utils-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/commons-lang-2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/commons-lang-2.4.jar
--------------------------------------------------------------------------------
/build/pmd/dom4j-1.6.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/dom4j-1.6.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-ant-task-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-ant-task-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-command-line-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-command-line-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-command-line-api-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-command-line-api-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-core-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-core-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-cpd-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-cpd-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-cpd-ant-task-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-cpd-ant-task-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-cpd-command-line-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-cpd-command-line-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-files-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-files-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-metrics-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-metrics-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-metrics-ant-task-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-metrics-ant-task-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-metrics-command-line-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-metrics-command-line-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-ruleset-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-ruleset-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/flex-pmd-ruleset-api-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/flex-pmd-ruleset-api-1.1.jar
--------------------------------------------------------------------------------
/build/pmd/jsap-2.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/jsap-2.1.jar
--------------------------------------------------------------------------------
/build/pmd/plexus-utils-1.0.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/plexus-utils-1.0.2.jar
--------------------------------------------------------------------------------
/build/pmd/pmd-4.2.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/build/pmd/pmd-4.2.5.jar
--------------------------------------------------------------------------------
/libs/flexunit-4.1.0-33-as3_3.5.0.12683.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/libs/flexunit-4.1.0-33-as3_3.5.0.12683.swc
--------------------------------------------------------------------------------
/libs/flexunit-cilistener-4.1.0-33-3.5.0.12683.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/libs/flexunit-cilistener-4.1.0-33-3.5.0.12683.swc
--------------------------------------------------------------------------------
/libs/flexunit-uilistener-4.1.0-33-3.5.0.12683.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/libs/flexunit-uilistener-4.1.0-33-3.5.0.12683.swc
--------------------------------------------------------------------------------
/libs/hamcrest-as3-flex-1.1.3.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/libs/hamcrest-as3-flex-1.1.3.swc
--------------------------------------------------------------------------------
/libs/mockolate-0.9.3.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/libs/mockolate-0.9.3.swc
--------------------------------------------------------------------------------
/src/.gitignore:
--------------------------------------------------------------------------------
1 | FlexUnitApplication.mxml
--------------------------------------------------------------------------------
/src/deprecated/.gitignore:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/deprecated/confine.as:
--------------------------------------------------------------------------------
1 | package deprecated
2 | {
3 | [Deprecated(replacement="utils.number.clamp")]
4 |
5 | /**
6 | * Restricts the value
to the min
and max
7 | * @param value the number to restrict
8 | * @param min the minimum number for value
to be
9 | * @param max the maximum number for value
to be
10 | * @return
11 | */
12 | public function confine(value:Number, min:Number, max:Number):Number {
13 | return value < min ? min : (value > max ? max : value);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/deprecated/getURL.as:
--------------------------------------------------------------------------------
1 | package deprecated {
2 | import flash.net.URLRequest;
3 | import flash.net.navigateToURL;
4 |
5 |
6 |
7 | [Deprecated(replacement="utils.location.openURL")]
8 | /**
9 | * getURL for ActionScript 3.0. Similar
10 | * to getURL of ActionScript 2.0 in simplicity
11 | * and ease. Errors are suppressed and traced
12 | * to the output window.
13 | *
14 | * @author Trevor McCauley - www.senocular.com
15 | */ public function getURL(url:String, target:String = null):void {
16 |
17 | try {
18 | navigateToURL(new URLRequest(url), target);
19 | }
20 | catch(error:Error) {
21 | trace("[getURL] " + error);
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/deprecated/randomBoolean.as:
--------------------------------------------------------------------------------
1 | package deprecated {
2 | [Deprecated(replacement="utils.boolean.randomChance")]
3 |
4 |
5 | /**
6 | * Returns a Boolean.
7 | * Example code:
8 | *
9 | * RandomUtils.boolean(); // returns true or false (50% chance of true) 10 | *11 | * Another example code: 12 | *
13 | * RandomUtils.boolean(0.8); // returns true or false (80% chance of true) 14 | *15 | * @param chance Chance Number (0-1) 16 | * @return Float Number between min-max exclusive. 17 | * @author Aaron Clinger 18 | * @author Shane McCartney 19 | * @author David Nelson 20 | */ public function randomBoolean(chance:Number = 0.5):Boolean { 21 | return(Math.random() < chance); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/deprecated/randomRangeFloat.as: -------------------------------------------------------------------------------- 1 | package deprecated { 2 | [Deprecated(replacement="utils.number.randomWithinRange")] 3 | 4 | 5 | /** 6 | * Returns a random float number within a given range 7 | */ public function randomRangeFloat(min:Number, max:Number):Number { 8 | return Math.random() * (max - min) + min; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/deprecated/randomRangeInt.as: -------------------------------------------------------------------------------- 1 | package deprecated { 2 | [Deprecated(replacement="utils.number.randomIntegerWithinRange")] 3 | 4 | 5 | 6 | /** 7 | * Returns a random int number within a given range 8 | */ public function randomRangeInt(min:Number, max:Number):Number { 9 | return Math.floor(Math.random() * (max - min + 1) + min); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/utils/align/alignCenter.as: -------------------------------------------------------------------------------- 1 | package utils.align { 2 | import flash.display.DisplayObject; 3 | 4 | /** 5 | * Center align object to target. 6 | */ 7 | public function alignCenter(item:DisplayObject, target:DisplayObject):void { 8 | xAlignCenter(item, target); 9 | yAlignCenter(item, target); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/utils/align/getPositionToTheRightOf.as: -------------------------------------------------------------------------------- 1 | package utils.align 2 | { 3 | import flash.display.DisplayObject; 4 | 5 | import utils.ratio.widthToHeight; 6 | 7 | /** 8 | * Gets the position to the right of an object based on its width and x position 9 | * with an optional gap. 10 | * 11 | * This is useful when you need to cause object B to appear 20px to the right of object A. 12 | * 13 | * B.x = getPositionToTheRightOf(A, 20); 14 | * 15 | * @param displayObject An object to get the position under. 16 | * @param gap An optional amount to space out the position under. 17 | */ 18 | public function getPositionToTheRightOf(displayObject:DisplayObject, gap:int = 0):int { 19 | return displayObject.x + displayObject.width + gap; 20 | } 21 | } -------------------------------------------------------------------------------- /src/utils/align/getPositionUnder.as: -------------------------------------------------------------------------------- 1 | package utils.align { 2 | import flash.display.DisplayObject; 3 | 4 | /** 5 | * Gets the position under an object based on its height and y position with an optional gap. 6 | * 7 | * This is useful when you need to cause object B to appear 20px below object A. 8 | * 9 | * B.y = getPositionUnder(A, 20); 10 | * 11 | * @param displayObject An object to get the position under. 12 | * @param gap An optional amount to space out the position under. 13 | */ 14 | public function getPositionUnder(displayObject:DisplayObject, gap:int = 0):int { 15 | return displayObject.y + displayObject.height + gap; 16 | } 17 | } -------------------------------------------------------------------------------- /src/utils/align/horizontalAlign.as: -------------------------------------------------------------------------------- 1 | package utils.align { 2 | 3 | 4 | 5 | /** 6 | * Convenient horizontal align method with optional alignment argument 7 | * @example
inArray
.
5 |
6 | @param inArray: Array composed only of numbers.
7 | @return The average of all numbers in the inArray
.
8 | @example
9 | items
in.
7 | @param items: Array of elements to search for.
8 | @return Returns true
if inArray
contains all elements of items
; otherwise false
.
9 | @example
10 |
11 | var numberArray:Array = new Array(1, 2, 3, 4, 5);
12 | trace(ArrayUtil.containsAll(numberArray, new Array(1, 3, 5)));
13 |
14 | */
15 | public function containsAll(inArray:Array, items:Array):Boolean
16 | {
17 | var l:uint = items.length;
18 |
19 | while (l--)
20 | if (inArray.indexOf(items[l]) == -1)
21 | return false;
22 |
23 | return true;
24 | }
25 | }
--------------------------------------------------------------------------------
/src/utils/array/copyArray.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | * Creates a copy of the specified array.
5 | *
6 | * Note that the array returned is a new array but the items within the
7 | * array are not copies of the items in the original array (but rather
8 | * references to the same items)
9 | *
10 | * @param arr The array that will be copies
11 | *
12 | * @return A new array which contains the same items as the array passed
13 | * in.
14 | *
15 | * @langversion ActionScript 3.0
16 | * @playerversion Flash 9.0
17 | * @tiptext
18 | */
19 | public function copyArray(arr:Array):Array
20 | {
21 | return arr.slice();
22 | }
23 | }
--------------------------------------------------------------------------------
/src/utils/array/equals.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Determines if two Arrays contain the same objects at the same index.
5 |
6 | @param first: First Array to compare to the second
.
7 | @param second: Second Array to compare to the first
.
8 | @return Returns true
if Arrays are the same; otherwise false
.
9 | */
10 | public function equals(first:Array, second:Array):Boolean
11 | {
12 | var i:uint = first.length;
13 | if (i != second.length)
14 | return false;
15 |
16 | while (i--)
17 | if (first[i] != second[i])
18 | return false;
19 |
20 | return true;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/utils/array/getHighestValue.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Finds the highest value in inArray
.
5 |
6 | @param inArray: Array composed only of numbers.
7 | @return The highest value in inArray
.
8 | @example
9 |
10 | var numberArray:Array = new Array(2, 1, 5, 4, 3);
11 | trace("The highest value is: " + ArrayUtil.getHighestValue(numberArray));
12 |
13 | */
14 | public function getHighestValue(inArray:Array):Number
15 | {
16 | return inArray[inArray.sort(16 | 8)[inArray.length - 1]];
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/array/getItemByKey.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Returns the first element that matches match
for the property key
.
5 |
6 | @param inArray: Array to search for an element with a key
that matches match
.
7 | @param key: Name of the property to match.
8 | @param match: Value to match against.
9 | @return Returns matched Object
; otherwise null
.
10 | */
11 | public function getItemByKey(inArray:Array, key:String, match:*):*
12 | {
13 | for each (var item:* in inArray)
14 | if (item[key] == match)
15 | return item;
16 |
17 | return null;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/utils/array/getItemByType.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Returns the first element that is compatible with a specific data type, clazz, or interface.
5 |
6 | @param inArray: Array to search for an element of a specific type.
7 | @param type: The type to compare the elements to.
8 | @return Returns all the matched elements.
9 | */
10 | public function getItemByType(inArray:Array, type:Class):*
11 | {
12 | for each (var item:* in inArray)
13 | if (item is type)
14 | return item;
15 |
16 | return null;
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/src/utils/array/getItemsByKey.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Returns every element that matches match
for the property key
.
5 |
6 | @param inArray: Array to search for object with key
that matches match
.
7 | @param key: Name of the property to match.
8 | @param match: Value to match against.
9 | @return Returns all the matched elements.
10 | */
11 | public function getItemsByKey(inArray:Array, key:String, match:*):Array
12 | {
13 | var t:Array = new Array();
14 |
15 | for each (var item:* in inArray)
16 | if (item[key] == match)
17 | t.push(item);
18 |
19 | return t;
20 | }
21 | }
--------------------------------------------------------------------------------
/src/utils/array/getItemsByType.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Returns every element that is compatible with a specific data type, clazz, or interface.
5 |
6 | @param inArray: Array to search for elements of a specific type.
7 | @param type: The type to compare the elements to.
8 | @return Returns all the matched elements.
9 | */
10 | public function getItemsByType(inArray:Array, type:Class):Array
11 | {
12 | var t:Array = new Array();
13 |
14 | for each (var item:* in inArray)
15 | if (item is type)
16 | t.push(item);
17 |
18 | return t;
19 | }
20 | }
--------------------------------------------------------------------------------
/src/utils/array/getLowestValue.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Finds the lowest value in inArray
.
5 |
6 | @param inArray: Array composed only of numbers.
7 | @return The lowest value in inArray
.
8 | @example
9 |
10 | var numberArray:Array = new Array(2, 1, 5, 4, 3);
11 | trace("The lowest value is: " + ArrayUtil.getLowestValue(numberArray));
12 |
13 | */
14 | public function getLowestValue(inArray:Array):Number
15 | {
16 | return inArray[inArray.sort(16 | 8)[0]];
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/array/getRandomElement.as:
--------------------------------------------------------------------------------
1 | package utils.array {
2 | import utils.number.randomIntegerWithinRange;
3 |
4 | /**
5 | * Returns a random element from an array.
6 | */
7 | public function getRandomElement(array:Array):* {
8 | return array[randomIntegerWithinRange(0, array.length-1)];
9 | }
10 | }
--------------------------------------------------------------------------------
/src/utils/array/removeDuplicates.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Creates new Array composed of only the non-identical elements of passed Array.
5 |
6 | @param inArray: Array to remove equivalent items.
7 | @return A new Array composed of only unique elements.
8 | @example
9 |
10 | var numberArray:Array = new Array(1, 2, 3, 4, 4, 4, 4, 5);
11 | trace(ArrayUtil.removeDuplicates(numberArray));
12 |
13 | */
14 | public function removeDuplicates(inArray:Array):Array
15 | {
16 | return inArray.filter(
17 | function(e:*, i:int, inArray:Array):Boolean
18 | {
19 | return (i == 0) ? true : inArray.lastIndexOf(e, i - 1) == -1;
20 | });
21 | }
22 | }
--------------------------------------------------------------------------------
/src/utils/array/removeValueFromArray.as:
--------------------------------------------------------------------------------
1 | package utils.array {
2 | /**
3 | * Remove all instances of the specified value from the array,
4 | *
5 | * @param arr The array from which the value will be removed
6 | *
7 | * @param value The object that will be removed from the array.
8 | *
9 | * @langversion ActionScript 3.0
10 | * @playerversion Flash 9.0
11 | * @tiptext
12 | */
13 | public function removeValueFromArray(arr:Array, value:Object):void {
14 | var len:uint = arr.length;
15 |
16 | for(var i:Number = len; i > -1; i--) {
17 | if(arr[i] == value) {
18 | arr.splice(i, 1);
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/utils/array/sum.as:
--------------------------------------------------------------------------------
1 | package utils.array
2 | {
3 | /**
4 | Adds all items in inArray
and returns the value.
5 |
6 | @param inArray: Array composed only of numbers.
7 | @return The total of all numbers in inArray
added.
8 | @example
9 |
10 | var numberArray:Array = new Array(2, 3);
11 | trace("Total is: " + ArrayUtil.sum(numberArray));
12 |
13 | */
14 | public function sum(inArray:Array):Number
15 | {
16 | var t:Number = 0;
17 | var l:uint = inArray.length;
18 |
19 | while (l--)
20 | t += inArray[l];
21 |
22 | return t;
23 | }
24 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertArrayContains.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | /**
4 | * Assert that the array contains the passed in item.
5 | */
6 | public function assertArrayContains(array:Array, item:*, message:String = ""):void
7 | {
8 | if (array.indexOf(item) == -1)
9 | {
10 | if (message == null || message.length == 0)
11 | {
12 | message = "[Assertion failed] - this Array argument does not contain the item '" + item + "'";
13 | }
14 | throw new Error(message);
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertArrayItemsTypeOf.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | /**
4 | * Assert that all items in the array are of the given type.
5 | *
6 | * @param array the array to check
7 | * @param type the type of the array items
8 | * @param message the error message to use if the assertion fails
9 | */
10 | public function assertArrayItemsTypeOf(array:Array, type:Class, message:String = ""):void
11 | {
12 | for each (var item:* in array)
13 | {
14 | if (!(item is type))
15 | {
16 | if (message == null || message.length == 0)
17 | {
18 | message = "[Assertion failed] - this Array must have items of type '" + type + "'";
19 | }
20 | throw new Error(message);
21 | }
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertDictionaryKeysTypeOf.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | import flash.utils.Dictionary;
4 |
5 | /**
6 | * Assert that the given Dictionary contains only keys of the given type.
7 | */
8 | public function assertDictionaryKeysTypeOf(dictionary:Dictionary, type:Class, message:String = ""):void
9 | {
10 | for (var key:Object in dictionary)
11 | {
12 | if (!(key is type))
13 | {
14 | if (message == null || message.length == 0)
15 | {
16 | message = "[Assertion failed] - this Dictionary argument must have keys of type '" + type + "'";
17 | }
18 | throw new Error(message);
19 | }
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertHasText.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | import utils.validation.isBlank;
4 |
5 | /**
6 | * Assert that the given String has valid text content; that is, it must not
7 | * be null
and must contain at least one non-whitespace character.
8 | *
9 | * @param text the String to check
10 | * @param message the exception message to use if the assertion fails
11 | * @see StringUtils#hasText
12 | */
13 | public function assertHasText(string:String, message:String = ""):void
14 | {
15 | if (isBlank(string))
16 | {
17 | if (message == null || message.length == 0)
18 | {
19 | message = "[Assertion failed] - this String argument must have text; it must not be null
, empty, or blank";
20 | }
21 | throw new Error(message);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertIsTrue.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | public function assertIsTrue(expression:Boolean, message:String = ""):void
4 | {
5 | if (!expression)
6 | {
7 | if (message == null || message.length == 0)
8 | {
9 | message = "[Assertion failed] - this expression must be true";
10 | }
11 | throw new Error(message);
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertNotNull.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | /**
4 | * Assert that an object is null
.
5 | * Assert.isNull(value, "The value must be null");6 | * @param object the object to check 7 | * @param message the error message to use if the assertion fails 8 | * @throws org.as3commons.lang.IllegalArgumentError if the object is not
null
9 | */
10 | public function assertNotNull(object:Object, message:String = ""):void
11 | {
12 | if (object == null)
13 | {
14 | if (message == null || message.length == 0)
15 | {
16 | message = "[Assertion failed] - this argument is required; it must not null";
17 | }
18 | throw new Error(message);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/utils/assert/assertState.as:
--------------------------------------------------------------------------------
1 | package utils.assert
2 | {
3 | /**
4 | * Assert a boolean expression to be true. If false, an IllegalStateError is thrown.
5 | * @param expression a boolean expression
6 | * @param the error message if the assertion fails
7 | */
8 | public function assertState(expression:Boolean, message:String = ""):void
9 | {
10 | if (!expression)
11 | {
12 | if (message == null || message.length == 0)
13 | {
14 | message = "[Assertion failed] - this state invariant must be true";
15 | }
16 | throw new Error(message);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/utils/boolean/randomBoolean.as:
--------------------------------------------------------------------------------
1 | package utils.boolean
2 | {
3 | /**
4 | * Randomly returns either true or false.
5 | *
6 | * @author Mims Wright
7 | */
8 | public function randomBoolean():Boolean
9 | {
10 | return randomChance(0.5);
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/boolean/randomChance.as:
--------------------------------------------------------------------------------
1 | package utils.boolean
2 | {
3 | /**
4 | * Randomly returns true "percent"% of the time (where percent is a decimal between 0.0 and 1.0).
5 | *
6 | * @author Mims Wright
7 | */
8 | public function randomChance(percent:Number):Boolean
9 | {
10 | return Math.random() < percent;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/capabilities/getPlayerInfo.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities
2 | {
3 | import flash.system.Capabilities;
4 |
5 | /**
6 | * Returns a player and environment info string.
7 | */
8 | public function getPlayerInfo():String
9 | {
10 | var debugger:String = (Capabilities.isDebugger) ? ' / Debugger' : '';
11 | var info:String =
12 | String("Flash Platform: " + Capabilities.version + " / " + Capabilities.playerType + debugger + " / " + Capabilities.os + " / " + Capabilities.screenResolutionX + "x" + Capabilities.screenResolutionY);
13 | return info;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/utils/capabilities/isAirApplication.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities {
2 | import flash.system.Capabilities;
3 |
4 |
5 |
6 | /**
7 | * Determines if the runtime environment is an Air application.
8 | * @return true if the runtime environment is an Air application
9 | * @author Aaron Clinger
10 | * @author Shane McCartney
11 | * @author David Nelson
12 | */
13 | public function isAirApplication():Boolean {
14 | return Capabilities.playerType == "Desktop";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/utils/capabilities/isIDE.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities {
2 | import flash.system.Capabilities;
3 |
4 |
5 |
6 | /**
7 | * Determines if the SWF is running in the IDE.
8 | * @return true if SWF is running in the Flash Player version used by the external player or test movie mode
9 | * @author Aaron Clinger
10 | * @author Shane McCartney
11 | * @author David Nelson
12 | */
13 | public function isIDE():Boolean {
14 | return Capabilities.playerType == "External";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/utils/capabilities/isMac.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities
2 | {
3 | import flash.system.Capabilities;
4 |
5 | /**
6 | * Indicates whether the running OS is a Mac
7 | * @return
8 | */
9 | public function isMac():Boolean
10 | {
11 | return Capabilities.os.toLowerCase().indexOf("mac os") != -1;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/capabilities/isPC.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities
2 | {
3 | import flash.system.Capabilities;
4 |
5 | /**
6 | * Indicates whether the running OS is a PC
7 | * @return
8 | */
9 | public function isPC():Boolean
10 | {
11 | return Capabilities.os.toLowerCase().indexOf("mac os") == -1;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/capabilities/isPlugin.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities {
2 | import flash.system.Capabilities;
3 |
4 |
5 |
6 | /**
7 | * Determines if the SWF is running in a browser plug-in.
8 | * @return true if SWF is running in the Flash Player browser plug-in
9 | * @author Aaron Clinger
10 | * @author Shane McCartney
11 | * @author David Nelson
12 | */
13 | public function isPlugin():Boolean {
14 | return Capabilities.playerType == "PlugIn" || Capabilities.playerType == "ActiveX";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/utils/capabilities/isStandAlone.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities {
2 | import flash.system.Capabilities;
3 |
4 |
5 |
6 | /**
7 | * Determines if the SWF is running in the StandAlone player.
8 | * @return true if SWF is running in the Flash StandAlone Player
9 | * @author Aaron Clinger
10 | * @author Shane McCartney
11 | * @author David Nelson
12 | */
13 | public function isStandAlone():Boolean {
14 | return Capabilities.playerType == "StandAlone";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/utils/capabilities/isWeb.as:
--------------------------------------------------------------------------------
1 | package utils.capabilities {
2 | import flash.display.DisplayObject;
3 |
4 |
5 |
6 | /**
7 | * Determines if the SWF is being served on the internet.
8 | * Example code:
9 | * 10 | * trace(isWeb(_root)); 11 | *12 | * @param location DisplayObject to get location of 13 | * @return true if SWF is being served on the internet 14 | * @author Aaron Clinger 15 | * @author Shane McCartney 16 | * @author David Nelson 17 | */ 18 | public function isWeb(location:DisplayObject):Boolean { 19 | return location.loaderInfo.url.substr(0, 4) == "http"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/utils/color/HSLtoHSV.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | /** 4 | * Convert HSL to HSV using RGB conversions: color preservation may be dubious. 5 | */ 6 | public function HSLtoHSV(hue:Number, luminance:Number, saturation:Number):Object 7 | { 8 | var rgbVal:Object = HSLtoRGB(hue, luminance, saturation); 9 | return RGBtoHSV(rgbVal.r, rgbVal.g, rgbVal.b); 10 | } 11 | } -------------------------------------------------------------------------------- /src/utils/color/HSLtoRGB.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | /** 4 | * Convert HSL values to RGB values. 5 | * @param hue 0 to 360. 6 | * @param luminance 0 to 1. 7 | * @param saturation 0 to 1. 8 | * @return Object with R,G,B values on 0 to 1 scale. 9 | */ 10 | public function HSLtoRGB(hue:Number, luminance:Number, saturation:Number):Object 11 | { 12 | var delta:Number; 13 | if (luminance < 0.5) 14 | { 15 | delta = saturation * luminance; 16 | } 17 | else 18 | { 19 | delta = saturation * (1 - luminance); 20 | } 21 | return HueToRGB(luminance - delta, luminance + delta, hue); 22 | } 23 | } -------------------------------------------------------------------------------- /src/utils/color/HSVtoHSL.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | /** 4 | * Convert HSV to HLS using RGB conversions: color preservation may be dubious. 5 | */ 6 | public function HSVtoHSL(hue:Number, saturation:Number, value:Number):Object 7 | { 8 | var rgbVal:Object = HSVtoRGB(hue, saturation, value); 9 | return RGBtoHSL(rgbVal.r, rgbVal.g, rgbVal.b); 10 | } 11 | } -------------------------------------------------------------------------------- /src/utils/color/HSVtoRGB.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | /** 4 | * Convert HSV values to RGB values. 5 | * @param hue on 0 to 360 scale. 6 | * @param saturation on 0 to 1 scale. 7 | * @param value on 0 to 1 scale. 8 | * @return Object with R,G,B values on 0 to 1 scale. 9 | */ 10 | public function HSVtoRGB(hue:Number, saturation:Number, value:Number):Object 11 | { 12 | var min:Number = (1 - saturation) * value; 13 | 14 | return HueToRGB(min, value, hue); 15 | } 16 | } -------------------------------------------------------------------------------- /src/utils/color/averageBlue.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Blue (RGB) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject 10 | * @param accuracy Percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average blue value on a scale of 0-255. 13 | */ 14 | public function averageBlue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int 15 | { 16 | return averageColorProperty(src, region, accuracy, 'b'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/averageGreen.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Green (RGB) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject 10 | * @param accuracy Percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average green value on a scale of 0-255. 13 | */ 14 | public function averageGreen(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int 15 | { 16 | return averageColorProperty(src, region, accuracy, 'g'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/averageHue.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Hue (HSL) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject 10 | * @param accuracy percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average hue value on a scale of 0-360. 13 | */ 14 | public function averageHue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int 15 | { 16 | return averageColorProperty(src, region, accuracy, 'h'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/averageLightness.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Lightness (HSL) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject 10 | * @param accuracy percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average lightness value on a scale of 0-255. 13 | */ 14 | public function averageLightness(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int 15 | { 16 | return averageColorProperty(src, region, accuracy, 'l'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/averageRed.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Red (RGB) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject. 10 | * @param accuracy Percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average red value on a scale of 0-255. 13 | */ 14 | public function averageRed(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int 15 | { 16 | return averageColorProperty(src, region, accuracy, 'r'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/averageSaturation.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Saturation (HSL) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject. 10 | * @param accuracy percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average saturation value on a scale of 0-1. 13 | */ 14 | public function averageSaturation(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):Number 15 | { 16 | return averageColorProperty(src, region, accuracy, 's'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/averageValue.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.geom.Rectangle; 5 | 6 | /** 7 | * Sample & average the Value (HSV) value from a display object or one of its region. 8 | * 9 | * @param src The DisplayObject 10 | * @param accuracy percentage of pixels to sample when averaging. 11 | * @param region to sample from [Default: null = entire src object]. 12 | * @return the sampled average lightness value on a scale of 0-1. 13 | */ 14 | public function averageValue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):Number 15 | { 16 | return averageColorProperty(src, region, accuracy, 'v'); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/color/changeContrast.as: -------------------------------------------------------------------------------- 1 | package utils.color { 2 | import utils.number.clamp; 3 | 4 | 5 | 6 | /** 7 | * Change the contrast of a hexadecimal Number by a certain increment 8 | * @param hex color value to shift contrast on 9 | * @param inc increment value to shift 10 | * @return new hex color value 11 | */ 12 | public function changeContrast(hex:Number, inc:Number):Number { 13 | var o:Object = getRGB(hex); 14 | o.r = clamp(o.r + inc, 0, 255); 15 | o.g = clamp(o.g + inc, 0, 255); 16 | o.b = clamp(o.b + inc, 0, 255); 17 | return toRGBComponents(o.r, o.g, o.b); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/utils/color/getARGB.as: -------------------------------------------------------------------------------- 1 | package utils.color 2 | { 3 | /** 4 | Converts a 32-bit ARGB color value into an ARGB object. 5 | 6 | @param color: The 32-bit ARGB color value. 7 | @return Returns an object with the properties a, r, g, and b defined. 8 | @example 9 |
10 | var myRGB:Object = ColorUtil.getRGB(0xFF00FF);
11 | trace("Red = " + myRGB.r);
12 | trace("Green = " + myRGB.g);
13 | trace("Blue = " + myRGB.b);
14 |
15 | */
16 | public function getRGB(color:uint):Object
17 | {
18 | var c:Object = {};
19 | c.r = color >> 16 & 0xFF;
20 | c.g = color >> 8 & 0xFF;
21 | c.b = color & 0xFF;
22 | return c;
23 | }
24 | }
--------------------------------------------------------------------------------
/src/utils/color/getTransform.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.geom.ColorTransform;
5 |
6 | /**
7 | * Returns the transform value set by the last setTransform() call.
8 | * @return An object containing the current offset and percentage values for the color.
9 | */
10 | public function getTransform(src:DisplayObject):Object
11 | {
12 | var ct:ColorTransform = src.transform.colorTransform;
13 | return { ra: ct.redMultiplier * 100, rb: ct.redOffset, ga: ct.greenMultiplier * 100, gb: ct.greenOffset, ba: ct.blueMultiplier * 100, bb: ct.blueOffset, aa: ct.alphaMultiplier * 100,
14 | ab: ct.alphaOffset };
15 | }
16 | }
--------------------------------------------------------------------------------
/src/utils/color/invertColor.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Inverts the color of the DisplayObject.
7 | */
8 | public function invertColor(src:DisplayObject):void
9 | {
10 | var t:Object = getTransform(src);
11 | setTransform(src, {
12 | ra: -t['ra'], ga: -t['ga'], ba: -t['ba'], rb: 255 - t['rb'], gb: 255 - t['gb'], bb: 255 - t['bb']
13 | });
14 | }
15 | }
--------------------------------------------------------------------------------
/src/utils/color/randomColor.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | /**
4 | * Returns a random color between 0x000000 and 0xFFFFFF
5 | *
6 | * @author Mims Wright
7 | */
8 | public function randomColor():uint {
9 | return uint(Math.random() * 0xFFFFFF);
10 | }
11 | }
--------------------------------------------------------------------------------
/src/utils/color/resetColor.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Reset the color of the DisplayObject to its original view (pre-ColorTransformed).
7 | */
8 | public function resetColor(src:DisplayObject):void
9 | {
10 | setTransform(src, { ra: 100, ga: 100, ba: 100, rb: 0, gb: 0, bb: 0 });
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/color/setARGB.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | public function setARGB(a:Number, r:Number, g:Number, b:Number):uint
4 | {
5 | var argb:uint = 0;
6 | argb += (a << 24);
7 | argb += (r << 16);
8 | argb += (g << 8);
9 | argb += (b);
10 | return argb;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/color/setColor.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.geom.ColorTransform;
5 |
6 | /**
7 | * Set the (A)RGB hexadecimal color value of a DisplayObject using ColorTransform.
8 | */
9 | public function setColor(src:DisplayObject, hex:uint):void
10 | {
11 | var ct:ColorTransform = src.transform.colorTransform;
12 | ct.color = hex;
13 | src.transform.colorTransform = ct;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/utils/color/toColor.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | /**
4 | * Parse a String representation of a color (hex or html) to uint.
5 | */
6 | public function toColor(str:String):uint
7 | {
8 | if (str.substr(0, 2) == '0x')
9 | {
10 | str = str.substr(2);
11 | }
12 | else if (str.substr(0, 1) == '#')
13 | {
14 | str = str.substr(1);
15 | }
16 | return parseInt(str, 16);
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/color/toGrayscale.as:
--------------------------------------------------------------------------------
1 | package utils.color
2 | {
3 | public function toGrayscale(hex:uint):uint
4 | {
5 | var color:Object = getARGB(hex);
6 | var c:Number = 0;
7 | c += color.r * .3;
8 | c += color.g * .59;
9 | c += color.b * .11;
10 | color.r = color.g = color.b = c;
11 | return setARGB(color.a, color.r, color.g, color.b);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/color/toHTML.as:
--------------------------------------------------------------------------------
1 | package utils.color {
2 |
3 |
4 |
5 | /**
6 | * Convert a hexadecimal number to a string representation with HTML notation: #rrggbb
.
7 | */
8 | public function toHTML(hex:uint):String {
9 | return "#" + (hex.toString(16)).toUpperCase();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/utils/color/toHexString.as:
--------------------------------------------------------------------------------
1 | package utils.color {
2 |
3 |
4 |
5 | /**
6 | * Convert a hexadecimal number to a string representation with ECMAScript notation: 0xrrggbb
.
7 | */
8 | public function toHexString(hex:uint):String {
9 | return "0x" + (hex.toString(16)).toUpperCase();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/utils/color/toRGBComponents.as:
--------------------------------------------------------------------------------
1 | package utils.color {
2 |
3 |
4 |
5 | /**
6 | * Convert individual R,G,B values to a hexadecimal value.
7 | */
8 | public function toRGBComponents(r:uint, g:uint, b:uint):uint {
9 | var hex:uint = 0;
10 | hex += (r << 16);
11 | hex += (g << 8);
12 | hex += (b);
13 | return hex;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/utils/conversion/bitsToBytes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts bits to bytes.
5 |
6 | @param bits: The number of bits.
7 | @return Returns the number of bytes.
8 | */
9 | public function bitsToBytes(bits:Number):Number
10 | {
11 | return bits / 8;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/bitsToKilobits.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts bits to kilobits.
5 |
6 | @param bits: The number of bits.
7 | @return Returns the number of kilobits.
8 | */
9 | public function bitsToKilobits(bits:Number):Number
10 | {
11 | return bits / 1024;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/bitsToKilobytes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts bits to kilobytes.
5 |
6 | @param bits: The number of bits.
7 | @return Returns the number of kilobits.
8 | */
9 | public function bitsToKilobytes(bits:Number):Number
10 | {
11 | return bits / 8192;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/bytesToBits.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts bytes to bits.
5 |
6 | @param bytes: The number of bytes.
7 | @return Returns the number of bits.
8 | */
9 | public function bytesToBits(bytes:Number):Number
10 | {
11 | return bytes * 8;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/bytesToKilobits.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts bytes to kilobits.
5 |
6 | @param bytes: The number of bytes.
7 | @return Returns the number of kilobits.
8 | */
9 | public function bytesToKilobits(bytes:Number):Number
10 | {
11 | return bytes / 128;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/bytesToKilobytes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts bytes to kilobytes.
5 |
6 | @param bytes: The number of bytes.
7 | @return Returns the number of kilobytes.
8 | */
9 | public function bytesToKilobytes(bytes:Number):Number
10 | {
11 | return bytes / 1024;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/daysToHours.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts days to hours.
5 |
6 | @param days: The number of days.
7 | @return Returns the number of hours.
8 | */
9 | public function daysToHours(days:Number):Number
10 | {
11 | return days * 24;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/daysToMilliseconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts days to milliseconds.
5 |
6 | @param days: The number of days.
7 | @return Returns the number of milliseconds.
8 | */
9 | public function daysToMilliseconds(days:Number):Number
10 | {
11 | return secondsToMilliseconds(daysToSeconds(days));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/daysToMinutes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts days to minutes.
5 |
6 | @param days: The number of days.
7 | @return Returns the number of minutes.
8 | */
9 | public function daysToMinutes(days:Number):Number
10 | {
11 | return hoursToMinutes(daysToHours(days));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/daysToSeconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts days to seconds.
5 |
6 | @param days: The number of days.
7 | @return Returns the number of seconds.
8 | */
9 | public function daysToSeconds(days:Number):Number
10 | {
11 | return minutesToSeconds(daysToMinutes(days));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/degreesToRadians.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts degrees to radians.
5 |
6 | @param degrees: The number of degrees.
7 | @return Returns the number of radians.
8 | */
9 | public function degreesToRadians(degrees:Number):Number
10 | {
11 | return degrees * (Math.PI / 180);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/hoursToDays.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts hours to days.
5 |
6 | @param hours: The number of hours.
7 | @return Returns the number of days.
8 | */
9 | public function hoursToDays(hours:Number):Number
10 | {
11 | return hours / 24;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/hoursToMilliseconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts hours to milliseconds.
5 |
6 | @param hours: The number of hours.
7 | @return Returns the number of milliseconds.
8 | */
9 | public function hoursToMilliseconds(hours:Number):Number
10 | {
11 | return secondsToMilliseconds(hoursToSeconds(hours));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/hoursToMinutes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts hours to minutes.
5 |
6 | @param hours: The number of hours.
7 | @return Returns the number of minutes.
8 | */
9 | public function hoursToMinutes(hours:Number):Number
10 | {
11 | return hours * 60;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/hoursToSeconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts hours to seconds.
5 |
6 | @param hours: The number of hours.
7 | @return Returns the number of seconds.
8 | */
9 | public function hoursToSeconds(hours:Number):Number
10 | {
11 | return minutesToSeconds(hoursToMinutes(hours));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/kilobitsToBits.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts kilobits to bits.
5 |
6 | @param kilobits: The number of kilobits.
7 | @return Returns the number of bits.
8 | */
9 | public function kilobitsToBits(kilobits:Number):Number
10 | {
11 | return kilobits * 1024;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/kilobitsToBytes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts kilobits to bytes.
5 |
6 | @param kilobits: The number of kilobits.
7 | @return Returns the number of bytes.
8 | */
9 | public function kilobitsToBytes(kilobits:Number):Number
10 | {
11 | return kilobits * 128;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/kilobitsToKilobytes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts kilobits to kilobytes.
5 |
6 | @param kilobytes: The number of kilobits.
7 | @return Returns the number of kilobytes.
8 | */
9 | public function kilobitsToKilobytes(kilobits:Number):Number
10 | {
11 | return kilobits / 8;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/kilobytesToBits.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts kilobytes to bits.
5 |
6 | @param kilobytes: The number of kilobytes.
7 | @return Returns the number of bits.
8 | */
9 | public function kilobytesToBits(kilobytes:Number):Number
10 | {
11 | return kilobytes * 8192;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/kilobytesToBytes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts kilobytes to bytes.
5 |
6 | @param kilobytes: The number of kilobytes.
7 | @return Returns the number of bytes.
8 | */
9 | public function kilobytesToBytes(kilobytes:Number):Number
10 | {
11 | return kilobytes * 1024;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/kilobytesToKilobits.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts kilobytes to kilobits.
5 |
6 | @param kilobytes: The number of kilobytes.
7 | @return Returns the number of kilobits.
8 | */
9 | public function kilobytesToKilobits(kilobytes:Number):Number
10 | {
11 | return kilobytes * 8;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/millisecondsToDays.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 |
4 | /**
5 | Converts milliseconds to days.
6 |
7 | @param milliseconds: The number of milliseconds.
8 | @return Returns the number of days.
9 | */
10 | public function millisecondsToDays(milliseconds:Number):Number
11 | {
12 | return hoursToDays(millisecondsToHours(milliseconds));
13 | }
14 | }
--------------------------------------------------------------------------------
/src/utils/conversion/millisecondsToHours.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts milliseconds to hours.
5 |
6 | @param milliseconds: The number of milliseconds.
7 | @return Returns the number of hours.
8 | */
9 | public function millisecondsToHours(milliseconds:Number):Number
10 | {
11 | return minutesToHours(millisecondsToMinutes(milliseconds));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/millisecondsToMinutes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts milliseconds to minutes.
5 |
6 | @param milliseconds: The number of milliseconds.
7 | @return Returns the number of minutes.
8 | */
9 | public function millisecondsToMinutes(milliseconds:Number):Number
10 | {
11 | return secondsToMinutes(millisecondsToSeconds(milliseconds));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/millisecondsToSeconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts milliseconds to seconds.
5 |
6 | @param milliseconds: The number of milliseconds.
7 | @return Returns the number of seconds.
8 | */
9 | public function millisecondsToSeconds(milliseconds:Number):Number
10 | {
11 | return milliseconds / 1000;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/minutesToDays.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts minutes to days.
5 |
6 | @param minutes: The number of minutes.
7 | @return Returns the number of days.
8 | */
9 | public function minutesToDays(minutes:Number):Number
10 | {
11 | return hoursToDays(minutesToHours(minutes));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/minutesToHours.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts minutes to hours.
5 |
6 | @param minutes: The number of minutes.
7 | @return Returns the number of hours.
8 | */
9 | public function minutesToHours(minutes:Number):Number
10 | {
11 | return minutes / 60;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/minutesToMilliseconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts minutes to milliseconds.
5 |
6 | @param minutes: The number of minutes.
7 | @return Returns the number of milliseconds.
8 | */
9 | public function minutesToMilliseconds(minutes:Number):Number
10 | {
11 | return secondsToMilliseconds(minutesToSeconds(minutes));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/minutesToSeconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts minutes to seconds.
5 |
6 | @param minutes: The number of minutes.
7 | @return Returns the number of seconds.
8 | */
9 | public function minutesToSeconds(minutes:Number):Number
10 | {
11 | return minutes * 60;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/radiansToDegrees.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts radians to degrees.
5 |
6 | @param radians: The number of radians.
7 | @return Returns the number of degrees.
8 | */
9 | public function radiansToDegrees(radians:Number):Number
10 | {
11 | return radians * (180 / Math.PI);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/secondsToDays.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts seconds to days.
5 |
6 | @param seconds: The number of seconds.
7 | @return Returns the number of days.
8 | */
9 | public function secondsToDays(seconds:Number):Number
10 | {
11 | return hoursToDays(secondsToHours(seconds));
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/secondsToHours.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 |
4 | /**
5 | Converts seconds to hours.
6 |
7 | @param seconds: The number of seconds.
8 | @return Returns the number of hours.
9 | */
10 | public function secondsToHours(seconds:Number):Number
11 | {
12 | return minutesToHours(secondsToMinutes(seconds));
13 | }
14 | }
--------------------------------------------------------------------------------
/src/utils/conversion/secondsToMilliseconds.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts seconds to milliseconds.
5 |
6 | @param seconds: The number of seconds.
7 | @return Returns the number of milliseconds.
8 | */
9 | public function secondsToMilliseconds(seconds:Number):Number
10 | {
11 | return seconds * 1000;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/conversion/secondsToMinutes.as:
--------------------------------------------------------------------------------
1 | package utils.conversion
2 | {
3 | /**
4 | Converts seconds to minutes.
5 |
6 | @param seconds: The number of seconds.
7 | @return Returns the number of minutes.
8 | */
9 | public function secondsToMinutes(seconds:Number):Number
10 | {
11 | return seconds / 60;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/cookie/getCookie.as:
--------------------------------------------------------------------------------
1 | package utils.cookie
2 | {
3 | import flash.external.ExternalInterface;
4 |
5 | public function getCookie(cookieName:String):String
6 | {
7 | var r:String = "";
8 | var search:String = cookieName + "=";
9 | var js:String = "function get_cookie(){return document.cookie;}";
10 | var o:Object = ExternalInterface.call(js);
11 | var cookieVariable:String = o.toString();
12 |
13 | if (cookieVariable.length > 0)
14 | {
15 | var offset:int = cookieVariable.indexOf(search);
16 | if (offset != -1)
17 | {
18 | offset += search.length;
19 | var end:int = cookieVariable.indexOf(";", offset);
20 | if (end == -1)
21 | end = cookieVariable.length;
22 | r = unescape(cookieVariable.substring(offset, end));
23 | }
24 | }
25 | return r;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/utils/cookie/setCookie.as:
--------------------------------------------------------------------------------
1 | package utils.cookie
2 | {
3 | import flash.external.ExternalInterface;
4 |
5 | public function setCookie(cookieName:String, cookieValue:String):void
6 | {
7 | var js:String = "function sc(){";
8 | js += "var c = escape('" + cookieName + "') + '=' + escape('" + cookieValue + "') + '; path=/';";
9 | js += "document.cookie = c;";
10 | js += "}";
11 | ExternalInterface.call(js);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/date/addWeeks.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function addWeeks(date:Date, weeks:uint):Date
4 | {
5 | date.date += weeks * 7;
6 | return date;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/utils/date/ceil.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Returns the rounded up date where the time is 12:00am.
5 | * If a date is not provided, the current date is used.
6 | * @param date the date to round up
7 | * @return
8 | */
9 | public function ceil(date:Date = null):Date
10 | {
11 | if (!date)
12 | date = new Date();
13 |
14 | date.date += 1.0;
15 | date.hours = 0.0;
16 | date.minutes = 0.0;
17 | date.seconds = 0.0;
18 | date.milliseconds = 0.0;
19 |
20 | return date;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/utils/date/clone.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function clone(date:Date):Date
4 | {
5 | return new Date(date.fullYear, date.month, date.date, date.hours, date.minutes, date.seconds, date.milliseconds);
6 | }
7 | }
--------------------------------------------------------------------------------
/src/utils/date/dayAbbrNames.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 |
3 |
4 | public const dayAbbrNames:Array = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
5 |
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/utils/date/dayNames.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public const dayNames:Array = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
4 | }
--------------------------------------------------------------------------------
/src/utils/date/equals.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Determines if two Dates are the same time.
5 |
6 | @param first: First Date to compare to second
.
7 | @param second: Second Date to compare to first
.
8 | @return Returns true
if Dates are the same; otherwise false
.
9 | */
10 | public function equals(first:Date, second:Date):Boolean
11 | {
12 | return first.valueOf() == second.valueOf();
13 | }
14 | }
--------------------------------------------------------------------------------
/src/utils/date/floor.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Returns the rounded down date where the time is 12:00am.
5 | * If a date is not provided, the current date is used.
6 | * @param date the date to round down
7 | * @return
8 | */
9 | public function floor(date:Date = null):Date
10 | {
11 | if (!date)
12 | date = new Date();
13 |
14 | date.hours = 0.0;
15 | date.minutes = 0.0;
16 | date.seconds = 0.0;
17 | date.milliseconds = 0.0;
18 |
19 | return date;
20 | }
21 | }
--------------------------------------------------------------------------------
/src/utils/date/formatWeekOf.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function formatWeekOf(date:Date):String
4 | {
5 | date = getLastSunday(date);
6 |
7 | var string:String = "";
8 | string = "Week of " + String(date.getUTCMonth() + 1) + "/" + String(date.getUTCDate());
9 |
10 | return string;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/date/getAMPM.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Returns a string indicating whether the date represents a time in the
5 | * ante meridiem (AM) or post meridiem (PM).
6 | *
7 | * If the hour is less than 12 then "AM" will be returned.
8 | *
9 | * If the hour is greater than 12 then "PM" will be returned.
10 | *
11 | * @param d1 The Date from which to generate the 12 hour clock indicator.
12 | *
13 | * @return A String ("AM" or "PM") indicating which half of the day the
14 | * hour represents.
15 | *
16 | * @langversion ActionScript 3.0
17 | * @playerversion Flash 9.0
18 | * @tiptext
19 | */
20 | public function getAMPM(d:Date):String
21 | {
22 | return (d.hours > 11) ? "PM" : "AM";
23 | }
24 | }
--------------------------------------------------------------------------------
/src/utils/date/getDayAbbrName.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 |
3 |
4 |
5 | /**
6 | * Returns the English abbreviation name of the provided day.
7 | * @param day the index of the day, where zero returns 'Sun' and six returns 'Sat'
8 | * @return
9 | */
10 | public function getDayAbbrName(day:int):String {
11 | return dayAbbrNames[day];
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/utils/date/getDayAsString.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function getDayAsString(day:Number):String
4 | {
5 | var dayNamesFull:Array = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
6 | return dayNamesFull[day];
7 | }
8 | }
--------------------------------------------------------------------------------
/src/utils/date/getDayName.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Returns the English name of the provided day.
5 | * @param day the index of the day, where zero returns 'Sunday' and six returns 'Saturday'
6 | * @return
7 | */
8 | public function getDayName(day:int):String
9 | {
10 | return dayNames[day];
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/date/getDayOfTheYear.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Gets the current day out of the total days in the year (starting from 0).
5 |
6 | @param d: Date object to find the current day of the year from.
7 | @return Returns the current day of the year (0-364 or 0-365 on a leap year).
8 | */
9 | public function getDayOfTheYear(d:Date):uint
10 | {
11 | var firstDay:Date = new Date(d.getFullYear(), 0, 1);
12 | return (d.getTime() - firstDay.getTime()) / 86400000;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/utils/date/getDaysInMonth.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Finds the number of days in the given month.
5 |
6 | @param year: The full year.
7 | @param month: The month number (0 for January, 1 for February, and so on).
8 | @return The number of days in the month; 28 through 31.
9 | @example
10 |
11 | var myDate:Date = new Date(2000, 0, 1);
12 |
13 | trace(DateUtil.getDaysInMonth(myDate.getFullYear(), myDate.getMonth())); // Traces 31
14 |
15 | */
16 | public function getDaysInMonth(year:Number, month:Number):uint
17 | {
18 | return (new Date(year, ++month, 0)).getDate();
19 | }
20 | }
--------------------------------------------------------------------------------
/src/utils/date/getFormattedDifferenceFromUTC.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 | import utils.conversion.minutesToHours;
3 | import utils.number.addLeadingZeroes;
4 |
5 |
6 |
7 | /**
8 | * Formats the difference to coordinated undefined time (UTC).
9 | * @param date Date object to find the time zone offset of
10 | * @param separator Character(s) that separates the hours from minutes
11 | * @return Formatted time difference from UTC
12 | */
13 | public function getFormattedDifferenceFromUTC(date:Date, separator:String = ""):String {
14 | var pre:String = (-date.getTimezoneOffset() < 0) ? "-" : "+";
15 |
16 | return pre + addLeadingZeroes(Math.floor(minutesToHours(date.getTimezoneOffset()))) + separator + addLeadingZeroes(date.getTimezoneOffset() % 60);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/utils/date/getInternetTime.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | import utils.conversion.minutesToHours;
4 | import utils.conversion.secondsToHours;
5 |
6 | /**
7 | Converts current time into Swatch internet time or beats.
8 |
9 | @param d: Date object to convert.
10 | @return Returns time in beats (0 to 999).
11 | */
12 | public function getInternetTime(d:Date):Number
13 | {
14 | var beats:uint = ((d.getUTCHours() + 1 + minutesToHours(d.getUTCMinutes()) + secondsToHours(d.getUTCSeconds())) / 0.024);
15 | return (beats > 1000) ? beats - 1000 : beats;
16 | }
17 | }
--------------------------------------------------------------------------------
/src/utils/date/getLastMonday.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function getLastMonday(date:Date):Date
4 | {
5 | date.date -= (date.day - 1);
6 |
7 | return date;
8 | }
9 | }
--------------------------------------------------------------------------------
/src/utils/date/getLastSunday.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function getLastSunday(date:Date):Date
4 | {
5 | var temp:Date = clone(date);
6 |
7 | temp.date -= temp.day;
8 |
9 | return temp;
10 | }
11 | }
--------------------------------------------------------------------------------
/src/utils/date/getLatestDate.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Compares dates and returns the latest one.
5 | *
6 | * @param dates that will be compared.
7 | * @return The latest date.
8 | *
9 | * @langversion ActionScript 3.0
10 | * @playerversion Flash 9.0
11 | * @author Mims H. Wright
12 | */
13 | public function getLatestDate(... dates ):Date
14 | {
15 | var latestDate:Date;
16 | if (dates.length() == 0) {
17 | throw new ArgumentError("Requires at least one argument");
18 | }
19 | for each (var date:Date in dates) {
20 | if (!latestDate) {
21 | latestDate = date;
22 | continue;
23 | }
24 |
25 | if (date.getTime() > latestDate.getTime()) {
26 | latestDate = date;
27 | }
28 | }
29 | return latestDate;
30 | }
31 | }
--------------------------------------------------------------------------------
/src/utils/date/getMeridiem.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Determines if time is Ante meridiem or Post meridiem.
5 |
6 | @param hours: The hour to find the meridiem of (an integer from 0 to 23).
7 | @return Returns either "AM"
or "PM"
8 | @example
9 |
10 | trace(DateUtil.getMeridiem(17)); // Traces PM
11 |
12 | */
13 | public function getMeridiem(hours:Number):String
14 | {
15 | return (hours < 12) ? 'AM' : 'PM';
16 | }
17 | }
--------------------------------------------------------------------------------
/src/utils/date/getMonthAbbrName.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 |
3 |
4 |
5 | /**
6 | * Returns the English abbreviation name of the provided month.
7 | * @param month the index of the month, starting at zero
8 | * @return
9 | */
10 | public function getMonthAbbrName(month:int):String {
11 | return monthAbbrNames[month];
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/utils/date/getMonthName.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Returns the English name of the provided month.
5 | * @param month the index of the month, starting at zero
6 | * @return
7 | */
8 | public function getMonthName(month:int):String
9 | {
10 | return monthNames[month];
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/date/getNextDay.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /** Returns the next calender date following the provided Date.
4 | * If no Date is provided, the current date is used.
5 | * @param startDate The date you wish to get the next day of
6 | * @return
7 | */
8 | public function getNextDay(startDate:Date=null):Date
9 | {
10 | const millisecondsPerDay:int = 1000 * 60 * 60 * 24;
11 |
12 | if(!startDate)
13 | startDate = new Date();
14 |
15 | //scrub the time of day
16 | var tmpDate:Date = new Date(startDate.getFullYear(),
17 | startDate.getMonth(),
18 | startDate.getDate());
19 |
20 | tmpDate.setTime(tmpDate.getTime() + millisecondsPerDay);
21 | return tmpDate;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/utils/date/getPreviousDay.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /** Returns the previous calender date to the provided Date.
4 | * If no Date is provided, the current date is used.
5 | * @param startDate The date you wish to get the previous day of
6 | * @return
7 | */
8 | public function getPreviousDay(startDate:Date=null):Date
9 | {
10 | const millisecondsPerDay:int = 1000 * 60 * 60 * 24;
11 |
12 | if(!startDate)
13 | startDate = new Date();
14 |
15 | //scrub the time of day
16 | var tmpDate:Date = new Date(startDate.getFullYear(),
17 | startDate.getMonth(),
18 | startDate.getDate());
19 | return new Date(tmpDate.getTime() - millisecondsPerDay);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/utils/date/getStartOfWeek.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function getStartOfWeek(date:Date):Date
4 | {
5 | var temp:Date = clone(date);
6 |
7 | temp.date -= temp.day;
8 | temp = makeMorning(temp);
9 |
10 | return temp;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/date/getTimeBetween.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Determines the difference between two dates.
5 |
6 | @param startDate: The starting date.
7 | @param endDate: The ending date.
8 | @return Returns the difference in milliseconds between the two dates.
9 | @example
10 |
11 | trace(ConversionUtil.millisecondsToDays(DateUtil.getTimeBetween(new Date(2007, 0, 1), new Date(2007, 0, 11)))); // Traces 10
12 |
13 | */
14 | public function getTimeBetween(startDate:Date, endDate:Date):Number
15 | {
16 | return endDate.getTime() - startDate.getTime();
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/date/getTimezone.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Determines the time zone of the user from a Date object.
5 |
6 | @param d: Date object to find the time zone of.
7 | @return Returns the time zone abbreviation.
8 | @example
9 |
10 | trace(DateUtil.getTimezone(new Date()));
11 |
12 | */
13 | public function getTimezone(d:Date):String
14 | {
15 | var timeZones:Array =
16 | new Array('IDLW', 'NT', 'HST', 'AKST', 'PST', 'MST', 'CST', 'EST', 'AST', 'ADT', 'AT', 'WAT', 'GMT', 'CET', 'EET', 'MSK', 'ZP4', 'ZP5', 'ZP6', 'WAST', 'WST', 'JST', 'AEST', 'AEDT',
17 | 'NZST');
18 | var hour:uint = Math.round(12 + -(d.getTimezoneOffset() / 60));
19 |
20 | if (isDaylightSavings(d))
21 | hour--;
22 |
23 | return timeZones[hour];
24 | }
25 | }
--------------------------------------------------------------------------------
/src/utils/date/getUTCDate.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Sort of converts a date into UTC.
5 | */
6 | public function getUTCDate(d:Date):Date
7 | {
8 | var nd:Date = new Date();
9 | var offset:Number = d.getTimezoneOffset() * 60 * 1000;
10 | nd.setTime(d.getTime() + offset);
11 | return nd;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/date/isDaylightSavings.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Determines if or not the date is in daylight saving time.
5 |
6 | @param d: Date to find if it is during daylight savings time.
7 | @return Returns true
if daylight savings time; otherwise false
.
8 | */
9 | public function isDaylightSavings(d:Date):Boolean
10 | {
11 | var months:uint = 12;
12 | var offset:uint = d.getTimezoneOffset();
13 | var offsetCheck:Number;
14 |
15 | while (months--)
16 | {
17 | offsetCheck = (new Date(d.getFullYear(), months, 1)).getTimezoneOffset();
18 |
19 | if (offsetCheck != offset)
20 | return (offsetCheck > offset);
21 | }
22 |
23 | return false;
24 | }
25 | }
--------------------------------------------------------------------------------
/src/utils/date/isInCurrentWeek.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public function isInCurrentWeek(date:Date):Boolean
4 | {
5 | var today:Date = new Date();
6 | var startOfWeek:Date = getStartOfWeek(today);
7 |
8 | var millisecondsDifference:Number = getTimeBetween(startOfWeek, date);
9 |
10 | var b:Boolean;
11 | b = millisecondsDifference < TimeRelationships.WEEK_IN_MILLISECONDS;
12 | b &&= millisecondsDifference >= 0;
13 | return b;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/utils/date/isLeapYear.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | Determines if year is a leap year or a common year.
5 |
6 | @param year: The full year.
7 | @return Returns true
if year is a leap year; otherwise false
.
8 | @example
9 |
10 | var myDate:Date = new Date(2000, 0, 1);
11 |
12 | trace(DateUtil.isLeapYear(myDate.getFullYear())); // Traces true
13 |
14 | */
15 | public function isLeapYear(year:Number):Boolean
16 | {
17 | return getDaysInMonth(year, 1) == 29;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/utils/date/isPast.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Returns true if date is in the past.
5 | * If the date is exactly equal to the current time, it will return false.
6 | *
7 | * @author Mims H. Wright
8 | */
9 | public function isPast(date:Date):Boolean
10 | {
11 | return (new Date().getTime() - date.getTime()) > 0;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/date/makeMorning.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * Converts a date into just after midnight.
5 | */
6 | public function makeMorning(d:Date):Date
7 | {
8 | d = new Date(d.time);
9 | d.hours = 0;
10 | d.minutes = 0;
11 | d.seconds = 0;
12 | d.milliseconds = 0;
13 | return d;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/utils/date/makeNight.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 |
3 |
4 |
5 | /**
6 | * Converts a date into just before midnight.
7 | */
8 | public function makeNight(d:Date):Date {
9 | d = new Date(d.time);
10 | d.hours = 23;
11 | d.minutes = 59;
12 | d.seconds = 59;
13 | d.milliseconds = 999;
14 | return d;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/utils/date/monthAbbrNames.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 |
3 |
4 | public const monthAbbrNames:Array = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
5 |
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/utils/date/monthNames.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | public const monthNames:Array = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
4 | }
--------------------------------------------------------------------------------
/src/utils/date/timeCode.as:
--------------------------------------------------------------------------------
1 | package utils.date {
2 |
3 | /**
4 | * Utility function for generating time code given a number seconds.
5 | * @param sec Seconds
6 | * @return Timecode
7 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura)
8 | */
9 | public function timeCode(sec:Number):String {
10 | var h:Number = Math.floor(sec / 3600);
11 | var m:Number = Math.floor((sec % 3600) / 60);
12 | var s:Number = Math.floor((sec % 3600) % 60);
13 |
14 | return (h == 0 ? ""
15 | : (h < 10 ? "0" + String(h) + ":" : String(h) + ":"))
16 | + (m < 10 ? "0" + String(m) : String(m)) + ":"
17 | + (s < 10 ? "0" + String(s) : String(s));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/utils/date/toggleAMPM.as:
--------------------------------------------------------------------------------
1 | package utils.date
2 | {
3 | /**
4 | * If a date is AM, changes it to PM and vice versa.
5 | *
6 | * @author Mims H. Wright
7 | *
8 | * @param date The Date to flip.
9 | * @returns A new date object, 12 hours later or earlier depending.
10 | */
11 | public function toggleAMPM(date:Date):Date
12 | {
13 | var d:Date = new Date(date.time);
14 | if (getAMPM(date) == "PM") {
15 | d.hours -= 12;
16 | } else {
17 | d.hours += 12;
18 | }
19 | return d;
20 | }
21 | }
--------------------------------------------------------------------------------
/src/utils/dictionary/getKeys.as:
--------------------------------------------------------------------------------
1 | package utils.dictionary
2 | {
3 | import flash.utils.Dictionary;
4 |
5 | /**
6 | * Returns an Array of all keys within the specified dictionary.
7 | *
8 | * @param d The Dictionary instance whose keys will be returned.
9 | *
10 | * @return Array of keys contained within the Dictionary
11 | *
12 | * @langversion ActionScript 3.0
13 | * @playerversion Flash 9.0
14 | * @tiptext
15 | */
16 | public function getKeys(d:Dictionary):Array
17 | {
18 | var a:Array = new Array();
19 |
20 | for (var key:Object in d)
21 | {
22 | a.push(key);
23 | }
24 |
25 | return a;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/utils/dictionary/getValues.as:
--------------------------------------------------------------------------------
1 | package utils.dictionary
2 | {
3 | import flash.utils.Dictionary;
4 |
5 | /**
6 | * Returns an Array of all values within the specified dictionary.
7 | *
8 | * @param d The Dictionary instance whose values will be returned.
9 | *
10 | * @return Array of values contained within the Dictionary
11 | *
12 | * @langversion ActionScript 3.0
13 | * @playerversion Flash 9.0
14 | * @tiptext
15 | */
16 | public function getValues(d:Dictionary):Array
17 | {
18 | var a:Array = new Array();
19 |
20 | for each (var value:Object in d)
21 | {
22 | a.push(value);
23 | }
24 |
25 | return a;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/utils/display/applyNaturalScrollRect.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.geom.Rectangle;
5 |
6 | /**
7 | * Apply a scroll rect from (0,0) to (width,height)
8 | * @param dispObj Display object to apply on
9 | * @author Jackson Dunstan
10 | */
11 | public function applyNaturalScrollRect(dispObj:DisplayObject):void
12 | {
13 | dispObj.scrollRect = new Rectangle(0, 0, dispObj.width, dispObj.height);
14 | }
15 | }
--------------------------------------------------------------------------------
/src/utils/display/createBitmap.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.Bitmap;
4 | import flash.display.BitmapData;
5 | import flash.display.DisplayObject;
6 |
7 | /**
8 | * Returns a Bitmap instance of the supplied DisplayObject.
9 | */
10 | public function createBitmap(source:DisplayObject, useSmoothing:Boolean = true):Bitmap
11 | {
12 | const bitmapData:BitmapData = new BitmapData(source.width, source.height, true, 0xffffff);
13 | bitmapData.draw(source);
14 |
15 | const bitmap:Bitmap = new Bitmap(bitmapData);
16 | bitmap.smoothing = useSmoothing;
17 |
18 | return bitmap;
19 | }
20 | }
--------------------------------------------------------------------------------
/src/utils/display/cropBitmapData.as:
--------------------------------------------------------------------------------
1 | package utils.display {
2 |
3 | import flash.display.BitmapData;
4 | import flash.geom.Point;
5 | import flash.geom.Rectangle;
6 |
7 | /**
8 | * Crop the BitmapData source and return a new BitmapData.
9 | * @param source Source BitmapData
10 | * @param dest Crop area as Rectangle
11 | * @return Cropped source as BitmapData
12 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura)
13 | */
14 | public function cropBitmapData(source:BitmapData, dest:Rectangle):BitmapData {
15 | var o:BitmapData = new BitmapData(dest.width, dest.height);
16 | var point:Point = new Point(0, 0);
17 |
18 | o.copyPixels(source, dest, point);
19 |
20 | return o;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/utils/display/filterChildrenByProps.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.display.DisplayObjectContainer;
5 |
6 | public function filterChildrenByProps(container:DisplayObjectContainer, props:Object):Array
7 | {
8 | var filteredChildren:Array = [];
9 | var child:DisplayObject;
10 |
11 | for (var i:int = 0, l:int = container.numChildren; i < l; i++)
12 | {
13 | child = container.getChildAt(i);
14 | var isOK:Boolean = true;
15 | for (var prop:String in props)
16 | {
17 | if (child[prop] != props[prop])
18 | {
19 | isOK = false;
20 | break;
21 | }
22 | }
23 | if (isOK)
24 | filteredChildren.push(child);
25 | }
26 | return filteredChildren;
27 | }
28 | }
--------------------------------------------------------------------------------
/src/utils/display/findAncestor.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Search the ancestry for a specific parent object.
7 | * @param child The display object whose parents to check.
8 | * @param ancestor The ancestor to check for.
9 | * @return The ancestor or null.
10 | * @author Mims H. Wright
11 | */
12 | public function findAncestor(child:DisplayObject, ancestor:DisplayObject):DisplayObject
13 | {
14 | if (child == ancestor) { return ancestor; }
15 | if (child.parent == null) { return null; }
16 | if (child.parent == ancestor) { return ancestor; }
17 | return findAncestor(child.parent, ancestor);
18 | }
19 | }
--------------------------------------------------------------------------------
/src/utils/display/findAncestorWithType.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Search the ancestry for a specific parent object.
7 | * @param child The display object whose parents to check.
8 | * @param type The type to check for. Should be a class or interface.
9 | * @return The ancestor or null.
10 | * @author Mims H. Wright
11 | */
12 | public function findAncestorWithType(child:DisplayObject, type:*):*
13 | {
14 | if (child.parent == null) { return null; }
15 | if (child.parent is type) { return child.parent; }
16 | return findAncestorWithType(child.parent, type);
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/display/getChildren.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObjectContainer;
4 |
5 | /**
6 | * Get the children of a container as an array
7 | * @param container Container to get the children of
8 | * @return The children of the given container as an array
9 | * @author Jackson Dunstan
10 | */
11 | public function getChildren(container:DisplayObjectContainer):Array
12 | {
13 | var ret:Array = [];
14 |
15 | var numChildren:int = container.numChildren;
16 | for (var i:int = 0; i < numChildren; ++i)
17 | {
18 | ret.push(container.getChildAt(i));
19 | }
20 |
21 | return ret;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/utils/display/isVisible.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Check if a display object is visible. This checks all of its
7 | * parents' visibilities.
8 | * @param obj Display object to check
9 | * @author Jackson Dunstan
10 | */
11 | public function isVisible(obj:DisplayObject):Boolean
12 | {
13 | for (var cur:DisplayObject = obj; cur != null; cur = cur.parent)
14 | {
15 | if (!cur.visible)
16 | {
17 | return false;
18 | }
19 | }
20 | return true;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/utils/display/localToLocal.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.geom.Point;
5 |
6 | /**
7 | * Translate DisplayObject
container position in a new container.
8 | */
9 | public function localToLocal(from:DisplayObject, to:DisplayObject):Point
10 | {
11 | var point:Point = new Point();
12 | point = from.localToGlobal(point);
13 | point = to.globalToLocal(point);
14 | return point;
15 | }
16 | }
--------------------------------------------------------------------------------
/src/utils/display/moveBy.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Moves a display object by a given x and y position.
7 | * x and y parameters are optional and if either is omitted, the current position will not change.
8 | *
9 | * @author Mims Wright
10 | */
11 | public function moveBy(displayObject:DisplayObject, x:Number = NaN, y:Number = NaN):void
12 | {
13 | if (isNaN(x)) { x = 0; }
14 | if (isNaN(y)) { y = 0; }
15 | displayObject.x += x;
16 | displayObject.y += y;
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/display/moveTo.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | /**
6 | * Moves a display object to a given x and y position.
7 | * x and y parameters are optional and if either is omitted, the current position will not change.
8 | *
9 | * @author Mims Wright
10 | */
11 | public function moveTo(displayObject:DisplayObject, x:Number = NaN, y:Number = NaN):void
12 | {
13 | if (isNaN(x)) { x = displayObject.x; }
14 | if (isNaN(y)) { y = displayObject.y; }
15 | displayObject.x = x;
16 | displayObject.y = y;
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/display/originalHeight.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | public function originalHeight(obj:DisplayObject):Number
6 | {
7 | return obj.height / obj.scaleY;
8 | }
9 | }
--------------------------------------------------------------------------------
/src/utils/display/originalWidth.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | public function originalWidth(obj:DisplayObject):Number
6 | {
7 | return obj.width / obj.scaleX;
8 | }
9 | }
--------------------------------------------------------------------------------
/src/utils/display/relativePos.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.geom.Point;
5 |
6 | public function relativePos(dO1:DisplayObject, dO2:DisplayObject):Point
7 | {
8 | var pos:Point = new Point(0, 0);
9 | pos = dO1.localToGlobal(pos);
10 | pos = dO2.globalToLocal(pos);
11 | return pos;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/utils/display/removeAllChildren.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObjectContainer;
4 |
5 | /**
6 | * Remove all children from a container and leave the bottom few
7 | * @param container Container to remove from
8 | * @param leave (optional) Number of bottom children to leave
9 | * @author Jackson Dunstan
10 | */
11 | public function removeAllChildren(container:DisplayObjectContainer, leave:int = 0):void
12 | {
13 | while (container.numChildren > leave)
14 | {
15 | container.removeChildAt(leave);
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/display/scheduleForNextFrame.as:
--------------------------------------------------------------------------------
1 | package utils.display {
2 |
3 | import flash.display.Shape;
4 | import flash.events.Event;
5 |
6 | /**
7 | * Wait for a next frame.
8 | * Prevents high CPU state, when AVM doesn't send ENTER_FRAMES. It just simply waits until it gets one.
9 | * @param callback Function to call once when next frame is displayed
10 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura)
11 | */
12 | public function scheduleForNextFrame(callback:Function):void {
13 | var obj:Shape = new Shape();
14 |
15 | obj.addEventListener(Event.ENTER_FRAME, function(ev:Event):void {
16 | obj.removeEventListener(Event.ENTER_FRAME, arguments.callee);
17 | callback();
18 | });
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/utils/display/setProperties.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 |
5 | public function setProperties(children:Array, props:Object):void
6 | {
7 | var child:DisplayObject;
8 | for (var i:int = 0, l:int = children.length; i < l; i++)
9 | {
10 | child = children[i];
11 | for (var prop:String in props)
12 | {
13 | child[prop] = props[prop];
14 | }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/utils/display/sumProps.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | public function sumProps(children:Array, prop:String):Number
4 | {
5 | var sum:Number = 0;
6 | for (var i:int = 0, l:int = children.length; i < l; i++)
7 | {
8 | sum += children[i][prop];
9 | }
10 | return sum;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/display/transformToFitRect.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.DisplayObject;
4 | import flash.geom.Rectangle;
5 |
6 | /**
7 | * Moves and resizes a display object to fit within a rectangle.
8 | *
9 | * @author Mims Wright
10 | */
11 | public function transformToFitRect(displayObject:DisplayObject, rectangle:Rectangle):void
12 | {
13 | displayObject.x = rectangle.x;
14 | displayObject.y = rectangle.y;
15 | displayObject.width = rectangle.width;
16 | displayObject.height = rectangle.height;
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/display/wait.as:
--------------------------------------------------------------------------------
1 | package utils.display
2 | {
3 | import flash.display.Shape;
4 | import flash.events.Event;
5 |
6 | /**
7 | * Wait a given number of frames then call a callback
8 | * @param numFrames Number of frames to wait before calling the callback
9 | * @param callback Function to call once the given number of frames have passed
10 | * @author Jackson Dunstan
11 | */
12 | public function wait(numFrames:uint, callback:Function):void
13 | {
14 | var obj:Shape = new Shape();
15 | obj.addEventListener(
16 | Event.ENTER_FRAME,
17 | function(ev:Event):void
18 | {
19 | numFrames--;
20 | if (numFrames == 0)
21 | {
22 | obj.removeEventListener(Event.ENTER_FRAME, arguments.callee);
23 | callback();
24 | }
25 | }
26 | );
27 | }
28 | }
--------------------------------------------------------------------------------
/src/utils/error/getStackTrace.as:
--------------------------------------------------------------------------------
1 | package utils.error
2 | {
3 | /**
4 | * Get a stack trace
5 | * @return A stack trace
6 | * @author Jackson Dunstan
7 | */
8 | public function getStackTrace():String
9 | {
10 | return new Error().getStackTrace();
11 | }
12 | }
--------------------------------------------------------------------------------
/src/utils/frame/getFrameNumberForLabel.as:
--------------------------------------------------------------------------------
1 | package utils.frame
2 | {
3 | import flash.display.MovieClip;
4 |
5 | /**
6 | Determines the frame number for the specified label.
7 |
8 | @param target: The MovieClip to search for the frame label in.
9 | @param label: The name of the frame label.
10 | @return The frame number of the label or -1
if the frame label was not found.
11 | */
12 | public function getFrameNumberForLabel(target:MovieClip, label:String):int
13 | {
14 | var labels:Array = target.currentLabels;
15 | var l:int = labels.length;
16 |
17 | while (l--)
18 | if (labels[l].name == label)
19 | return labels[l].frame;
20 |
21 | return -1;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/utils/fullscreen/toggleFullScreen.as:
--------------------------------------------------------------------------------
1 | package utils.fullscreen
2 | {
3 | import flash.display.Stage;
4 | import flash.display.StageDisplayState;
5 |
6 | /**
7 | * Toggles the stage display state between normal and fullscreen.
8 | *
9 | * @param stage A reference to the stage object.
10 | * @returns String The new state.
11 | *
12 | * @author Mims Wright
13 | */
14 | public function toggleFullScreen(stage:Stage):String
15 | {
16 | var state:String;
17 | if (stage.displayState == StageDisplayState.FULL_SCREEN) {
18 | state = StageDisplayState.NORMAL;
19 | } else {
20 | state = StageDisplayState.FULL_SCREEN;
21 | }
22 | stage.displayState = state;
23 | return state;
24 | }
25 | }
--------------------------------------------------------------------------------
/src/utils/garbageCollection/gc.as:
--------------------------------------------------------------------------------
1 | package utils.garbageCollection
2 | {
3 | import flash.net.LocalConnection;
4 |
5 | // TODO: Needs documentation
6 | public function gc():void
7 | {
8 | try
9 | {
10 | new LocalConnection().connect("gc");
11 | new LocalConnection().connect("gc");
12 | }
13 | catch (e:Error)
14 | {
15 | var shouldTouchHere:Boolean = true;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/geom/Side.as:
--------------------------------------------------------------------------------
1 | package utils.geom
2 | {
3 | /**
4 | * An enumeration of the four sides of a rectangle.
5 | * Useful for working with tile engines, creating borders, etc.
6 | */
7 | public class Side
8 | {
9 | public static const TOP:int = 1;
10 | public static const BOTTOM:int = 2;
11 | public static const LEFT:int = 4;
12 | public static const RIGHT:int = 8;
13 |
14 | public static const NONE:int = 0;
15 | public static const ALL:int = TOP | BOTTOM | LEFT | RIGHT;
16 | }
17 | }
--------------------------------------------------------------------------------
/src/utils/geom/angle.as:
--------------------------------------------------------------------------------
1 | package utils.geom
2 | {
3 | import flash.geom.Point;
4 |
5 | /**
6 | Determines the angle/degree between the first and second point.
7 |
8 | @param first: The first Point.
9 | @param second: The second Point.
10 | @return The degree between the two points.
11 | */
12 | public function angle(first:Point, second:Point):Number
13 | {
14 | return Math.atan2(second.y - first.y, second.x - first.x) / (Math.PI / 180);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/utils/geom/cartesianToPolarCoordinates.as:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by IntelliJ IDEA.
3 | * User: Ian McLean
4 | * Date: Sep 30, 2010
5 | * Time: 11:56:07 AM
6 | */
7 | package utils.geom {
8 |
9 | /**
10 | Converts cartesian coordinates to polar coordinates.
11 |
12 | @param x: The x value of the cartesian point.
13 | @param y: The y value of the cartesian point.
14 | @return Returns an array containing polar coordinates r and q.
15 | */
16 |
17 | public function cartesianToPolarCoordinates(x:Number, y:Number) : Array {
18 |
19 | var r:Number = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
20 | var q:Number = Math.atan(y/x) * (180/Math.PI);
21 |
22 | return [r, q];
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/src/utils/geom/getRectangleCenter.as:
--------------------------------------------------------------------------------
1 | package utils.geom {
2 | import flash.geom.Point;
3 | import flash.geom.Rectangle;
4 |
5 | //TODO: Author?
6 |
7 | /**
8 | * Calculates center Point of a Rectangle.
9 | *
10 | * @param value Rectangle to determine center Point of
11 | */
12 | public function getRectangleCenter(value:Rectangle):Point {
13 | return new Point(value.x + (value.width / 2), value.y + (value.height / 2));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/utils/geom/getRectanglePerimeter.as:
--------------------------------------------------------------------------------
1 | package utils.geom
2 | {
3 | import flash.geom.Rectangle;
4 |
5 | /**
6 | Calculates the perimeter of a rectangle.
7 |
8 | @param rect: Rectangle to determine the perimeter of.
9 | */
10 | public function getRectanglePerimeter(rect:Rectangle):Number
11 | {
12 | return rect.width * 2 + rect.height * 2;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/utils/geom/polarToCartesianCoordinates.as:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by IntelliJ IDEA.
3 | * User: Ian McLean
4 | * Date: Sep 30, 2010
5 | * Time: 1:00:51 PM
6 | */
7 | package utils.geom {
8 | import flash.geom.Point;
9 |
10 | /**
11 | * Converts polar coordinates to cartesian coordinates.
12 | * @param r The r value of the polar coordinate.
13 | * @param q The q value of the polar coordinate in degrees.
14 | */
15 |
16 | public function polarToCartesianCoordinates(r:Number, q:Number) : Point {
17 |
18 | var asRadian:Number = q * Math.PI/180;
19 |
20 | var x:Number = r * Math.cos(asRadian);
21 | var y:Number = r * Math.sin(asRadian);
22 |
23 | return new Point(x,y);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/src/utils/geom/randomPoint.as:
--------------------------------------------------------------------------------
1 | package utils.geom
2 | {
3 | import flash.geom.Point;
4 |
5 | import utils.number.randomIntegerWithinRange;
6 |
7 | /**
8 | * Returns a randomly generated point (containing int values)
9 | *
10 | * @author Mims H. Wright
11 | */
12 | public function randomPoint(xLow:int, xHigh:int, yLow:int, yHigh:int):Point {
13 | return new Point(
14 | randomIntegerWithinRange(xLow, xHigh),
15 | randomIntegerWithinRange(yLow, yHigh)
16 | );
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/geom/reverseRectangle.as:
--------------------------------------------------------------------------------
1 | package utils.geom {
2 | import flash.geom.Rectangle;
3 |
4 |
5 | // TODO: What's the point of this? Does this even work? Can a rect have a negative width or height?
6 | // TODO: Author?
7 |
8 | /**
9 | * Reverse a rectangle.
10 | *
11 | * @param value Source rectangle
12 | * @return Reversed rectangle
13 | */
14 | public function reverseRectangle(value:Rectangle):Rectangle {
15 | return new Rectangle(value.left, value.top, -value.width, -value.height);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/utils/geom/roundPoint.as:
--------------------------------------------------------------------------------
1 | package utils.geom {
2 | import flash.geom.Point;
3 |
4 | // todo: author?
5 |
6 | /**
7 | * Returns a new point with x and y values rounded down to the nearest int.
8 | *
9 | * @param value Source Point to be rounded.
10 | * @return Point A new point with x and y rounded down to an int.
11 | */
12 | public function roundPoint(point:Point):Point {
13 | return new Point(int(point.x), int(point.y));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/utils/geom/simplifyAngle.as:
--------------------------------------------------------------------------------
1 | package utils.geom {
2 |
3 | /**
4 | * Simplifies the supplied angle to its simplest representation.
5 | * Example code:
6 | * 7 | * var simpAngle:Number = simplifyAngle(725); // returns 5 8 | * var simpAngle2:Number = simplifyAngle(-725); // returns -5 9 | *10 | * @param angle Angle to simplify in degrees 11 | * @return Supplied angle simplified 12 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura) 13 | */ 14 | public function simplifyAngle(angle:Number):Number { 15 | var _rotations:Number = Math.floor(angle / 360); 16 | 17 | return (angle >= 0) ? angle - (360 * _rotations) : angle + (360 * _rotations); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/utils/geom/trimAngle.as: -------------------------------------------------------------------------------- 1 | package utils.geom { 2 | 3 | /** 4 | * Trims the supplied angle to its 0..360 representation. 5 | * Example code: 6 | *
7 | * var simpAngle:Number = trimAngle(725); // returns 5 8 | *9 | * @param value Angle to trim 10 | * @return Supplied angle trimmed 11 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura) 12 | */ 13 | public function trimAngle(value:Number):Number { 14 | var a:Number = value; 15 | 16 | while(a < 0) a += 360; 17 | while(a > 360) a -= 360; 18 | 19 | return a; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/utils/html/a.as: -------------------------------------------------------------------------------- 1 | package utils.html 2 | { 3 | /** 4 | * Generate an A HREF tag. 5 | */ 6 | public function a(href:String, text:String, styleClass:String = null):String 7 | { 8 | return '" + text + ""; 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/html/br.as: -------------------------------------------------------------------------------- 1 | package utils.html 2 | { 3 | /** 4 | * Inset a BR with optional newline. 5 | */ 6 | public function br(addNewline:Boolean = false):String 7 | { 8 | return "
startTime
and elapsedTime
.
9 | @param startTime: Time in milliseconds when the load started.
10 | @param elapsedTime: Time in milliseconds since the load started or time when load completed.
11 | @return Bytes per second.
12 | @usageNote This method returns BYTES per second, not bits per second.
13 | */
14 | public function calculateBps(bytesLoaded:uint, startTime:uint, elapsedTime:uint):int
15 | {
16 | return Math.max(0, (bytesLoaded / millisecondsToSeconds(elapsedTime - startTime)));
17 | }
18 | }
--------------------------------------------------------------------------------
/src/utils/load/calculateKBps.as:
--------------------------------------------------------------------------------
1 | package utils.load
2 | {
3 | import utils.conversion.bytesToKilobytes;
4 |
5 | /**
6 | Calculates the load speed in kilobytes per second (kBps).
7 |
8 | @param bytesLoaded: Number of bytes that have loaded between startTime
and elapsedTime
.
9 | @param startTime: Time in milliseconds when the load started.
10 | @param elapsedTime: Time in milliseconds since the load started or time when load completed.
11 | @return Kilobytes per second.
12 | @usageNote This method returns kiloBYTES per second, not kilobits per second.
13 | */
14 | public function calculateKBps(bytesLoaded:uint, startTime:uint, elapsedTime:uint):Number
15 | {
16 | return bytesToKilobytes(calculateBps(bytesLoaded, startTime, elapsedTime));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/utils/location/locationNames.as:
--------------------------------------------------------------------------------
1 | package utils.location {
2 | public class locationNames {
3 |
4 |
5 | /** Firefox */
6 | public static const BROWSER_FIREFOX:String = "browserFirefox";
7 |
8 | /** Safari */
9 | public static const BROWSER_SAFARI:String = "browserSafari";
10 |
11 | /** Internet Explorer */
12 | public static const BROWSER_IE:String = "browserIE";
13 |
14 | /** Opera */
15 | public static const BROWSER_OPERA:String = "browserOpera";
16 |
17 | /** Undefined browser */
18 | public static const BROWSER_UNDEFINED:String = "browserUndefined";
19 |
20 | /** Standalone player */
21 | public static const STANDALONE_PLAYER:String = "standalonePlayer";
22 |
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/utils/location/windowNames.as:
--------------------------------------------------------------------------------
1 | package utils.location {
2 | public class windowNames {
3 |
4 |
5 | public static const WINDOW_SELF:String = "_self";
6 | public static const WINDOW_BLANK:String = "_blank";
7 | public static const WINDOW_PARENT:String = "_parent";
8 | public static const WINDOW_TOP:String = "_top";
9 |
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/utils/math/expressAsOdds.as:
--------------------------------------------------------------------------------
1 | package utils.math
2 | {
3 | /**
4 | * Expresses chances that an outcome will occur out of a number of total possible outcomes.
5 | *
6 | * @example 7 | * // number of kings in a deck of cards. 8 | * expressAsOdds(4, 52); // 1:13 9 | * 10 | * @author Mims Wright 11 | */ 12 | public function expressAsOdds(numberOfChances:int, allPossibleOutcomes:int):String { 13 | var _gcd:int = gcd(numberOfChances, allPossibleOutcomes); 14 | return (numberOfChances / _gcd) + ":" + (allPossibleOutcomes / _gcd); 15 | } 16 | } -------------------------------------------------------------------------------- /src/utils/math/gcd.as: -------------------------------------------------------------------------------- 1 | package utils.math 2 | { 3 | /** 4 | * Returns the greatest common devisor between two ints. 5 | * 6 | * @author Mims Wright 7 | */ 8 | public function gcd(a:int, b:int):int { 9 | if (b == 0) { 10 | return a; 11 | } 12 | return gcd (b, a%b); 13 | } 14 | } -------------------------------------------------------------------------------- /src/utils/mvc/AbstractModel.as: -------------------------------------------------------------------------------- 1 | package utils.mvc 2 | { 3 | import flash.events.EventDispatcher; 4 | import flash.events.IEventDispatcher; 5 | 6 | /** 7 | * Specifies the minimum functionality that the "model" of 8 | * a Model/View/Controller triad must provide. 9 | * 10 | * @author Mims Wright 11 | */ 12 | public class AbstractModel extends EventDispatcher implements IModel 13 | { 14 | public function AbstractModel() 15 | { 16 | super(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/utils/mvc/IModel.as: -------------------------------------------------------------------------------- 1 | package utils.mvc 2 | { 3 | import flash.events.IEventDispatcher; 4 | 5 | /** 6 | * Specifies the minimum functionality that the "model" of 7 | * a Model/View/Controller triad must provide. 8 | * 9 | * @author Mims Wright 10 | */ 11 | public interface IModel extends IEventDispatcher 12 | { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/number/clamp.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | * Constrains a value to the defined numeric boundaries. 5 | * 6 | * @example7 | * clamp(3, 2, 5); // this will give back 3 since it's within the range 8 | * clamp(20, 2, 5); // this will give back 5 since 5 is the upper boundary 9 | * clamp(-5, 2, 5); // this will give back 2 since 2 is the lower boundary 10 | * 11 | * 12 | * @author Mims Wright 13 | */ 14 | public function clamp(val:Number, min:Number, max:Number):Number 15 | { 16 | return Math.max(Math.min(val, max), min); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/number/fastMax2.as: -------------------------------------------------------------------------------- 1 | package utils.number { 2 | 3 | 4 | 5 | /** 6 | * Get fast max for two numbers. 7 | * @param val1 Number A 8 | * @param val2 Number B 9 | * @return Max 10 | * @author Jackson Dunstan (http://jacksondunstan.com/articles/445) 11 | */ 12 | public function fastMax2(val1:Number, val2:Number):Number { 13 | if((!(val1 <= 0) && !(val1 > 0)) || (!(val2 <= 0) && !(val2 > 0))) return NaN; 14 | return val1 > val2 ? val1 : val2; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/number/fastMin2.as: -------------------------------------------------------------------------------- 1 | package utils.number { 2 | 3 | 4 | 5 | /** 6 | * Get fast min for two numbers. 7 | * @param val1 Number A 8 | * @param val2 Number B 9 | * @return Min 10 | * @author Jackson Dunstan (http://jacksondunstan.com/articles/445) 11 | */ 12 | public function fastMin2(val1:Number, val2:Number):Number { 13 | if((!(val1 <= 0) && !(val1 > 0)) || (!(val2 <= 0) && !(val2 > 0))) return NaN; 14 | return val1 < val2 ? val1 : val2; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/number/hexChars.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | [ExcludeClass] 4 | /** String for quick lookup of a hex character based on index */ 5 | public const hexChars:String = "0123456789abcdef"; 6 | } -------------------------------------------------------------------------------- /src/utils/number/interpolate.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | import utils.math.Percent; 4 | 5 | /** 6 | Determines a value between two specified values. 7 | 8 | @param amount: The level of interpolation between the two values. If0%
,begin
value is returned; if100%
,end
value is returned. 9 | @param minimum: The lower value. 10 | @param maximum: The upper value. 11 | @example 12 |13 | trace(NumberUtil.interpolate(new Percent(0.5), 0, 10)); // Traces 5 14 |
15 | */ 16 | public function interpolate(amount:Percent, minimum:Number, maximum:Number):Number 17 | { 18 | return minimum + (maximum - minimum) * amount.decimalPercentage; 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/number/isEqual.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Determines if the two values are equal, with the option to define the precision. 5 | 6 | @param val1: A value to compare. 7 | @param val2: A value to compare. 8 | @param precision: The maximum amount the two values can differ and still be considered equal. 9 | @return Returnstrue
the values are equal; otherwisefalse
. 10 | @example 11 |12 | trace(NumberUtil.isEqual(3.042, 3, 0)); // Traces false 13 | trace(NumberUtil.isEqual(3.042, 3, 0.5)); // Traces true 14 |
15 | */ 16 | public function isEqual(val1:Number, val2:Number, precision:Number = 0):Boolean 17 | { 18 | return Math.abs(val1 - val2) <= Math.abs(precision); 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/number/isEven.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Determines if the number is even. 5 | 6 | @param value: A number to determine if it is divisible by2
. 7 | @return Returnstrue
if the number is even; otherwisefalse
. 8 | @example 9 |10 | trace(NumberUtil.isEven(7)); // Traces false 11 | trace(NumberUtil.isEven(12)); // Traces true 12 |
13 | */ 14 | public function isEven(value:Number):Boolean 15 | { 16 | return (value & 1) == 0; 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/number/isInteger.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Determines if the number is an integer. 5 | 6 | @param value: A number to determine if it contains no decimal values. 7 | @return Returnstrue
if the number is an integer; otherwisefalse
. 8 | @example 9 |10 | trace(NumberUtil.isInteger(13)); // Traces true 11 | trace(NumberUtil.isInteger(1.2345)); // Traces false 12 |
13 | */ 14 | public function isInteger(value:Number):Boolean 15 | { 16 | return (value % 1) == 0; 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/number/isNegative.as: -------------------------------------------------------------------------------- 1 | package utils.number { 2 | 3 | 4 | 5 | /** 6 | * Determines whether or not the supplied Number is negative. 7 | * @param value Number to evaluate 8 | * @return Whether or not the supplied Number is negative 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function isNegative(value:Number):Boolean { 14 | return !isPositive(value); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/number/isOdd.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Determines if the number is odd. 5 | 6 | @param value: A number to determine if it is not divisible by2
. 7 | @return Returnstrue
if the number is odd; otherwisefalse
. 8 | @example 9 |10 | trace(NumberUtil.isOdd(7)); // Traces true 11 | trace(NumberUtil.isOdd(12)); // Traces false 12 |
13 | */ 14 | public function isOdd(value:Number):Boolean 15 | { 16 | return !isEven(value); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/number/isPositive.as: -------------------------------------------------------------------------------- 1 | package utils.number { 2 | 3 | 4 | 5 | /** 6 | * Determines whether or not the supplied Number is positive. 7 | * @param value Number to evaluate 8 | * @return Whether or not the supplied Number is positive 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function isPositive(value:Number):Boolean { 14 | return Boolean(value >= 0); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/number/isPrime.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Determines if the number is prime. 5 | 6 | @param value: A number to determine if it is only divisible by1
and itself. 7 | @return Returnstrue
if the number is prime; otherwisefalse
. 8 | @example 9 |10 | trace(NumberUtil.isPrime(13)); // Traces true 11 | trace(NumberUtil.isPrime(4)); // Traces false 12 |
13 | */ 14 | public function isPrime(value:Number):Boolean 15 | { 16 | if (value == 1 || value == 2) 17 | return true; 18 | 19 | if (isEven(value)) 20 | return false; 21 | 22 | var s:Number = Math.sqrt(value); 23 | for (var i:Number = 3; i <= s; i++) 24 | if (value % i == 0) 25 | return false; 26 | 27 | return true; 28 | } 29 | } -------------------------------------------------------------------------------- /src/utils/number/isRoughlyEqual.as: -------------------------------------------------------------------------------- 1 | package utils.number { 2 | 3 | /** 4 | * Returns true if the two numbers are within "maxPercentDifferent" percent of each other. 5 | * 6 | * @example7 | * isRoughlyEqual(0.7, 0.69); // true 8 | * isRoughlyEqual(0.7, 0.5); // false 9 | * 10 | * isRoughlyEqual(123456789, 123450000); // true 11 | * isRoughlyEqual(123456789, 100000000); // false 12 | * isRoughlyEqual(123456789, 100000000, 0.25); // true 13 | * 14 | * 15 | */ 16 | public function isRoughlyEqual ( a:Number, b:Number, maxPercentDifferent:Number = 0.10 ):Boolean { 17 | return Math.abs((a/b) - 1.0) < maxPercentDifferent; 18 | } 19 | } -------------------------------------------------------------------------------- /src/utils/number/map.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Maps a value from one coordinate space to another. 5 | 6 | @param value: Value from the input coordinate space to map to the output coordinate space. 7 | @param min1: Starting value of the input coordinate space. 8 | @param max1: Ending value of the input coordinate space. 9 | @param min2: Starting value of the output coordinate space. 10 | @param max2: Ending value of the output coordinate space. 11 | @example 12 |13 | trace(NumberUtil.map(0.75, 0, 1, 0, 100)); // Traces 75 14 |
15 | */ 16 | public function map(value:Number, min1:Number, max1:Number, min2:Number, max2:Number):Number 17 | { 18 | return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/number/normalize.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | import utils.math.Percent; 4 | 5 | /** 6 | Determines a percentage of a value in a given range. 7 | 8 | @param value: The value to be converted. 9 | @param minimum: The lower value of the range. 10 | @param maximum: The upper value of the range. 11 | @example 12 |13 | trace(NumberUtil.normalize(8, 4, 20).decimalPercentage); // Traces 0.25 14 |
15 | */ 16 | public function normalize(value:Number, minimum:Number, maximum:Number):Percent 17 | { 18 | return new Percent((value - minimum) / (maximum - minimum)); 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/number/randomIntegerWithinRange.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Creates a random integer within the defined range. 5 | 6 | @param min: The minimum value the random integer can be. 7 | @param min: The maximum value the random integer can be. 8 | @return Returns a random integer within the range. 9 | */ 10 | public function randomIntegerWithinRange(min:int, max:int):int 11 | { 12 | return Math.round(randomWithinRange(min, max)); 13 | } 14 | } -------------------------------------------------------------------------------- /src/utils/number/randomSign.as: -------------------------------------------------------------------------------- 1 | package utils.number { 2 | 3 | 4 | 5 | /** 6 | * Returns an int: -1 or 1. 7 | * Example code: 8 | *9 | * RandomUtils.sign(); // returns 1 or -1 (50% chance of 1) 10 | *11 | * Another example code: 12 | *13 | * RandomUtils.sign(0.8); // returns 1 or -1 (80% chance of 1) 14 | *15 | * @param chance Chance Number (0-1) 16 | * @return int: -1 or 1. 17 | * @author Aaron Clinger 18 | * @author Shane McCartney 19 | * @author David Nelson 20 | */ 21 | public function randomSign(chance:Number = 0.5):int { 22 | return(Math.random() < chance) ? 1 : -1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/utils/number/randomWithinRange.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | * Randomly generates a number in a range between min and max inclusively. 5 | * Automatically swaps max and min if min is higher than max. 6 | * 7 | * @param min The minimum value the random number can be. 8 | * @param min The maximum value the random number can be. 9 | * @return Returns a random number within the range. 10 | * 11 | * @author Mims Wright 12 | */ 13 | public function randomWithinRange(min:Number, max:Number):Number 14 | { 15 | if (min > max) { 16 | var temp:Number = max; 17 | max = min; 18 | min = temp; 19 | } 20 | return min + (Math.random() * (max - min)); 21 | } 22 | } -------------------------------------------------------------------------------- /src/utils/number/rol.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | * Rotates x left n bits 5 | * 6 | * @langversion ActionScript 3.0 7 | * @playerversion Flash 9.0 8 | * @tiptext 9 | */ 10 | public function rol(x:int, n:int):int 11 | { 12 | return (x << n) | (x >>> (32 - n)); 13 | } 14 | } -------------------------------------------------------------------------------- /src/utils/number/ror.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | * Rotates x right n bits 5 | * 6 | * @langversion ActionScript 3.0 7 | * @playerversion Flash 9.0 8 | * @tiptext 9 | */ 10 | public function ror(x:int, n:int):uint 11 | { 12 | var nn:int = 32 - n; 13 | return (x << nn) | (x >>> (32 - nn)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/number/round.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | * Rounds a number to the nearest nth, wheredigits
is n / 10. 5 | * @param value the number to round 6 | * @param digits the number of digits to show after the point 7 | * @return 8 | */ 9 | public function round(value:Number, digits:int):Number 10 | { 11 | digits = Math.pow(10, digits); 12 | 13 | return Math.round(value * digits) / digits; 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/number/roundDecimalToPlace.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | /** 4 | Rounds a number's decimal value to a specific place. 5 | 6 | @param value: The number to round. 7 | @param place: The decimal place to round. 8 | @return Returns the value rounded to the defined place. 9 | @example 10 |11 | trace(NumberUtil.roundToPlace(3.14159, 2)); // Traces 3.14 12 | trace(NumberUtil.roundToPlace(3.14159, 3)); // Traces 3.142 13 |
14 | */ 15 | public function roundDecimalToPlace(value:Number, place:uint):Number 16 | { 17 | var p:Number = Math.pow(10, place); 18 | 19 | return Math.round(value * p) / p; 20 | } 21 | } -------------------------------------------------------------------------------- /src/utils/object/assign.as: -------------------------------------------------------------------------------- 1 | package utils.object { 2 | 3 | 4 | 5 | /** 6 | * Assign properties from params to an Object. 7 | * @param obj Target Object 8 | * @param params Source Object 9 | * @return Resulting Object 10 | */ 11 | public function assign(obj:Object, params:Object):Object { 12 | var out:Object = (obj); 13 | 14 | for(var i:String in params) { 15 | //noinspection EmptyCatchBlockJS,UnusedCatchParameterJS 16 | try { 17 | out[i] = params[i]; 18 | } 19 | catch(err:Error) { 20 | } 21 | } 22 | 23 | return out; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/utils/object/combine.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Combines all of the properties from two objects into a single objects. Note that 5 | * duplicate properties will be overwritten by the values on the second parameter object. 6 | * 7 | * @param defaultVars 8 | * @param additionalVars 9 | * @return 10 | */ 11 | public function combine(defaultVars:Object, additionalVars:Object):Object 12 | { 13 | var combinedObject:Object = {}; 14 | var property:String; 15 | 16 | for (property in defaultVars) 17 | { 18 | combinedObject[property] = defaultVars[property]; 19 | } 20 | 21 | for (property in additionalVars) 22 | { 23 | combinedObject[property] = additionalVars[property]; 24 | } 25 | 26 | return combinedObject; 27 | } 28 | } -------------------------------------------------------------------------------- /src/utils/object/contains.as: -------------------------------------------------------------------------------- 1 | package utils.object { 2 | 3 | 4 | 5 | /** 6 | * Searches the first level properties of an Object for a another Object. 7 | * @param obj Object to search in. 8 | * @param member Object to search for. 9 | * @return true if Object was found 10 | * @author Aaron Clinger 11 | * @author Shane McCartney 12 | * @author David Nelson 13 | */ 14 | public function contains(obj:Object, member:Object):Boolean { 15 | for(var prop:String in obj) { 16 | if(obj[prop] == member) { 17 | return true; 18 | } 19 | } 20 | 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/utils/object/copy.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Copy an object 5 | * @param obj Object to copy 6 | * @param into (optional) Object to copy into. If null, a new object 7 | * is created. 8 | * @return A one-level deep copy of the object or null if the argument 9 | * is null 10 | * @author Jackson Dunstan 11 | */ 12 | public function copy(obj:Object, into:Object = null):Object 13 | { 14 | if (into == null) 15 | { 16 | into = {}; 17 | } 18 | if (obj != null) 19 | { 20 | for (var o:Object in obj) 21 | { 22 | into[o] = obj[o]; 23 | } 24 | } 25 | return into; 26 | } 27 | } -------------------------------------------------------------------------------- /src/utils/object/getKeys.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | Creates an Array comprised of all the keys in an Object. 5 | 6 | @param obj: Object in which to find keys. 7 | @return Array containing all the string key names. 8 | */ 9 | public function getKeys(obj:Object):Array 10 | { 11 | var keys:Array = new Array(); 12 | 13 | for (var i:String in obj) 14 | keys.push(i); 15 | 16 | return keys; 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/object/hasAnyProperties.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Check if an object has any properties 5 | * @param obj Object to check for properties 6 | * @return If the specified object has any properties. If the 7 | * specified object is null, this is false. 8 | * @author Jackson Dunstan 9 | */ 10 | public function hasAnyProperties(obj:Object):Boolean 11 | { 12 | for each (var prop:Object in obj) 13 | { 14 | return true; 15 | } 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/object/isNull.as: -------------------------------------------------------------------------------- 1 | package utils.object { 2 | /** 3 | Uses the strict equality operator to determine if object isnull
. 4 | 5 | @param obj: Object to determine ifnull
. 6 | @return Returnstrue
if object isnull
; otherwisefalse
. 7 | */ 8 | public function isNull(obj:Object):Boolean { 9 | return obj == null; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/utils/object/isSimple.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Returns whether or not the given object is simple data type. 5 | * 6 | * @param the object to check 7 | * @return true if the given object is a simple data type; false if not 8 | */ 9 | public function isSimple(object:Object):Boolean 10 | { 11 | switch (typeof(object)) 12 | { 13 | case "number": 14 | case "string": 15 | case "boolean": 16 | return true; 17 | case "object": 18 | return (object is Date) || (object is Array); 19 | } 20 | 21 | return false; 22 | } 23 | } -------------------------------------------------------------------------------- /src/utils/object/isUniformPropertyType.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Check if the properties of an object are all the same 5 | * @param obj Object whose properties should be checked 6 | * @param type Type to check the object's properties against 7 | * @return If all of the properties of the specified object are of the 8 | * specified type 9 | * @author Jackson Dunstan 10 | */ 11 | public function isUniformPropertyType(obj:Object, type:Class):Boolean 12 | { 13 | for each (var prop:Object in obj) 14 | { 15 | if (!(prop is type)) 16 | { 17 | return false; 18 | } 19 | } 20 | return true; 21 | } 22 | } -------------------------------------------------------------------------------- /src/utils/object/numProperties.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Count the properties in an object 5 | * @param obj Object to count the properties of 6 | * @return The number of properties in the specified object. If the 7 | * specified object is null, this is 0. 8 | * @author Jackson Dunstan 9 | */ 10 | public function numProperties(obj:Object):int 11 | { 12 | var count:int = 0; 13 | for each (var prop:Object in obj) 14 | { 15 | count++; 16 | } 17 | return count; 18 | } 19 | } -------------------------------------------------------------------------------- /src/utils/object/toArray.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | /** 4 | * Convert the object to an array. Note that the order of the array is 5 | * undefined. 6 | * @param obj Object to convert 7 | * @return An array with all of the properties of the given object or 8 | * null if the given object is null 9 | * @author Jackson Dunstan 10 | */ 11 | public function toArray(obj:Object):Array 12 | { 13 | if (obj == null) 14 | { 15 | return null; 16 | } 17 | else 18 | { 19 | var ret:Array = []; 20 | for each (var prop:Object in obj) 21 | { 22 | ret.push(prop); 23 | } 24 | return ret; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/utils/range/center.as: -------------------------------------------------------------------------------- 1 | package utils.range 2 | { 3 | // TODO: what is the purpose of this function? Needs documentation. 4 | public function center(a:Number, b:Number, c:Number):Number 5 | { 6 | if ((a > b) && (a > c)) 7 | { 8 | if (b > c) 9 | return b; 10 | else 11 | return c; 12 | } 13 | else if ((b > a) && (b > c)) 14 | { 15 | if (a > c) 16 | return a; 17 | else 18 | return c; 19 | } 20 | else if (a > b) 21 | { 22 | return a; 23 | } 24 | else 25 | { 26 | return b; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/utils/range/isInRange.as: -------------------------------------------------------------------------------- 1 | package utils.range 2 | { 3 | /** 4 | * Check if a number is in range. 5 | */ 6 | public function isInRange(n:Number, min:Number, max:Number, blacklist:Array = null):Boolean 7 | { 8 | if (!blacklist) 9 | blacklist = new Array(); 10 | if (blacklist.length > 0) 11 | { 12 | for (var i:String in blacklist) 13 | if (n == blacklist[i]) 14 | return false; 15 | } 16 | return (n >= min && n <= max); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/range/resolve.as: -------------------------------------------------------------------------------- 1 | package utils.range 2 | { 3 | /** 4 | * Resolve the number inside the range. If outside the range the nearest boundary value will be returned. 5 | */ 6 | public function resolve(val:Number, min:Number, max:Number):Number 7 | { 8 | return Math.max(Math.min(val, max), min); 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/ratio/defineRect.as: -------------------------------------------------------------------------------- 1 | package utils.ratio { 2 | import flash.geom.Rectangle; 3 | 4 | 5 | 6 | public function defineRect(size:Rectangle, width:Number, height:Number, snapToPixel:Boolean):Rectangle { 7 | var scaled:Rectangle = size.clone(); 8 | 9 | scaled.width = snapToPixel ? int(width) : width; 10 | scaled.height = snapToPixel ? int(height) : height; 11 | 12 | return scaled; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/utils/ratio/heightToWidth.as: -------------------------------------------------------------------------------- 1 | package utils.ratio { 2 | import flash.geom.Rectangle; 3 | 4 | 5 | 6 | /** 7 | * Determines the ratio of height to width. 8 | * @param rect Area's width and height expressed as a Rectangle - the Rectangle's x and y values are ignored 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function heightToWidth(rect:Rectangle):Number { 14 | return rect.height / rect.width; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/ratio/scaleHeight.as: -------------------------------------------------------------------------------- 1 | package utils.ratio { 2 | import flash.geom.Rectangle; 3 | 4 | 5 | /** 6 | * Scales the height of an area while preserving aspect ratio. 7 | * @param rect Area's width and height expressed as a Rectangle - the Rectangle's x and y values are ignored 8 | * @param width Width to scale to 9 | * @param snapToPixel true to force the scale to whole pixels, or false to allow sub-pixels 10 | * @author Aaron Clinger 11 | * @author Shane McCartney 12 | * @author David Nelson 13 | */ 14 | public function scaleHeight(rect:Rectangle, width:Number, snapToPixel:Boolean = true):Rectangle { 15 | return defineRect(rect, width, width * heightToWidth(rect), snapToPixel); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/utils/ratio/scaleWidth.as: -------------------------------------------------------------------------------- 1 | package utils.ratio { 2 | import flash.geom.Rectangle; 3 | 4 | /** 5 | * Scales the width of an area while preserving aspect ratio. 6 | * @param rect Area's width and height expressed as a Rectangle - the Rectangle's x and y values are ignored 7 | * @param height Height to scale to 8 | * @param snapToPixel true to force the scale to whole pixels, or false to allow sub-pixels 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function scaleWidth(rect:Rectangle, height:Number, snapToPixel:Boolean = true):Rectangle { 14 | return defineRect(rect, height * widthToHeight(rect), height, snapToPixel); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/ratio/widthToHeight.as: -------------------------------------------------------------------------------- 1 | package utils.ratio { 2 | import flash.geom.Rectangle; 3 | 4 | 5 | 6 | /** 7 | * Determines the ratio of width to height. 8 | * @param rect Area's width and height expressed as a Rectangle - the Rectangle's x and y values are ignored 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function widthToHeight(rect:Rectangle):Number { 14 | return rect.width / rect.height; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/utils/string/afterFirst.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Returns everything after the first occurrence of the provided character in the String. 7 | * @param value Input String 8 | * @param ch Character or sub-string 9 | * @returns Output String 10 | * @author Aaron Clinger 11 | * @author Shane McCartney 12 | * @author David Nelson 13 | */ 14 | public function afterFirst(value:String, ch:String):String { 15 | var out:String = ""; 16 | 17 | if(value) { 18 | var idx:int = value.indexOf(ch); 19 | 20 | if(idx != -1) { 21 | idx += ch.length; 22 | out = value.substr(idx); 23 | } 24 | } 25 | 26 | return out; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/utils/string/afterLast.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Returns everything after the last occurrence of the provided character in value. 7 | * @param value Input String 8 | * @param ch Character or sub-string 9 | * @return Output String 10 | * @author Aaron Clinger 11 | * @author Shane McCartney 12 | * @author David Nelson 13 | */ 14 | public function afterLast(value:String, ch:String):String { 15 | var out:String = ""; 16 | 17 | if(value) { 18 | var idx:int = value.lastIndexOf(ch); 19 | 20 | if(idx != -1) { 21 | idx += ch.length; 22 | out = value.substr(idx); 23 | } 24 | } 25 | 26 | return out; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/utils/string/arrayList.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Convert an Array to a list. 7 | * @param a Input Array 8 | * @return List as "item1, item2, item3" 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function arrayList(a:Array):String { 14 | var out:String = ""; 15 | 16 | for each(var i:String in a) { 17 | out += i + ", "; 18 | } 19 | 20 | return out.substr(0, out.length - 2); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/utils/string/beforeFirst.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Returns everything before the first occurrence of the provided character in the String. 7 | * @param value Input String 8 | * @param ch Character or sub-string 9 | * @returns Everything before the first occurence of the provided character in the String 10 | * @author Aaron Clinger 11 | * @author Shane McCartney 12 | * @author David Nelson 13 | */ 14 | public function beforeFirst(value:String, ch:String):String { 15 | var out:String = ""; 16 | 17 | if(value) { 18 | var idx:int = value.indexOf(ch); 19 | 20 | if(idx != -1) { 21 | out = value.substr(0, idx); 22 | } 23 | } 24 | 25 | return out; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/utils/string/beforeLast.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Returns everything before the last occurrence of the provided character in the String. 7 | * @param value Input String 8 | * @param ch Character or sub-string 9 | * @returns Everything before the last occurrence of the provided character in the String 10 | * @author Aaron Clinger 11 | * @author Shane McCartney 12 | * @author David Nelson 13 | */ 14 | public function beforeLast(value:String, ch:String):String { 15 | var out:String = ""; 16 | 17 | if(value) { 18 | var idx:int = value.lastIndexOf(ch); 19 | 20 | if(idx != -1) { 21 | out = value.substr(0, idx); 22 | } 23 | } 24 | 25 | return out; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/utils/string/beginsWith.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Determines whether the specified string begins with the specified prefix. 7 | * @param input The string that the prefix will be checked against. 8 | * @param prefix The prefix that will be tested against the string. 9 | * @returns True if the string starts with the prefix, false if it does not. 10 | * @langversion ActionScript 3.0 11 | * @playerversion Flash 9.0 12 | * @tiptext 13 | */ 14 | public function beginsWith(input:String, prefix:String):Boolean { 15 | return (prefix == input.substring(0, prefix.length)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/utils/string/constants.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | 4 | public class constants 5 | { 6 | public static const REGEX_UNSAFE_CHARS:String = "\\-^[]"; 7 | 8 | public static const TRIM_RIGHT_REGEX:RegExp = /[\s]+$/g; 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/string/convertBytesString.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | import utils.conversion.bytesToKilobytes; 4 | 5 | /** 6 | * Convert bytes to a String ("X B" or "X kB") 7 | * @param value Bytes count 8 | * @return Result String 9 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura) 10 | */ 11 | public function convertBytesString(value:uint):String { 12 | return (value <= 8192 ? (String(value) + " B") : (String(bytesToKilobytes(value)) + " kB")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/utils/string/detectBr.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Detect HTML line breaks. 5 | */ 6 | public function detectBr(str:String):Boolean 7 | { 8 | return str.split("
1; 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/string/endsWith.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Determines whether the specified string ends with the specified suffix. 7 | * @param input The string that the suffix will be checked against. 8 | * @param suffix The suffix that will be tested against the string. 9 | * @returns True if the string ends with the suffix, false if it does not. 10 | * @langversion ActionScript 3.0 11 | * @playerversion Flash 9.0 12 | * @tiptext 13 | */ 14 | public function endsWith(input:String, suffix:String):Boolean { 15 | return (suffix == input.substring(input.length - suffix.length)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/utils/string/equals.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Does a case insensitive compare or two strings and returns true if they are equal. 5 | */ 6 | public function equals(s1:String, s2:String, caseSensitive:Boolean = false):Boolean 7 | { 8 | return (caseSensitive) ? (s1 == s2) : (s1.toUpperCase() == s2.toUpperCase()); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /src/utils/string/firstToUpper.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Capitalize the first character in the string. 5 | */ 6 | public function firstToUpper(str:String):String 7 | { 8 | return str.charAt(0).toUpperCase() + str.substr(1); 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/string/getLettersFromString.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | public function getLettersFromString(source:String):String 4 | { 5 | var pattern:RegExp = /[^A-Z^a-z]/g; 6 | return source.replace(pattern, ''); 7 | } 8 | } -------------------------------------------------------------------------------- /src/utils/string/htmlDecode.as: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/src/utils/string/htmlDecode.as -------------------------------------------------------------------------------- /src/utils/string/htmlEncode.as: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/as3/as3-utils/838aad249f53afcfb88c2cdbba7004b07b1637e7/src/utils/string/htmlEncode.as -------------------------------------------------------------------------------- /src/utils/string/ltrim.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Removes whitespace from the front of the specified string. 7 | * 8 | * @param value The String whose beginning whitespace will will be removed. 9 | * 10 | * @returns A String with whitespace removed from the begining 11 | * 12 | * @langversion ActionScript 3.0 13 | * @playerversion Flash 9.0 14 | * @tiptext 15 | */ 16 | public function ltrim(value:String):String { 17 | var out:String = ""; 18 | 19 | if(value) { 20 | out = value.replace(/^\s+/, ""); 21 | } 22 | 23 | return out; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/utils/string/padLeft.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Pads value with specified padChar character to a specified length from the left. 7 | * @param value Input String 8 | * @param padChar Character for pad 9 | * @param length Length to pad to 10 | * @returns Padded String 11 | * @author Aaron Clinger 12 | * @author Shane McCartney 13 | * @author David Nelson 14 | */ 15 | public function padLeft(value:String, padChar:String, length:uint):String { 16 | var s:String = value; 17 | 18 | while(s.length < length) { 19 | s = padChar + s; 20 | } 21 | 22 | return s; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/utils/string/padRight.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Pads value with specified padChar character to a specified length from the right. 7 | * @param value Input String 8 | * @param padChar Character for pad 9 | * @param length Length to pad to 10 | * @returns Padded String 11 | * @author Aaron Clinger 12 | * @author Shane McCartney 13 | * @author David Nelson 14 | */ 15 | public function padRight(value:String, padChar:String, length:uint):String { 16 | var s:String = value; 17 | 18 | while(s.length < length) { 19 | s += padChar; 20 | } 21 | 22 | return s; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/utils/string/randomLowercaseCharacters.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Generate a set of random LowerCase characters. 5 | */ 6 | public function randomLowercaseCharacters(amount:Number):String 7 | { 8 | var str:String = ""; 9 | for (var i:int = 0; i < amount; i++) 10 | str += String.fromCharCode(Math.round(Math.random() * (122 - 97)) + 97); 11 | return str; 12 | } 13 | } -------------------------------------------------------------------------------- /src/utils/string/randomNumberString.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Generate a set of random Number characters. 5 | */ 6 | public function randomNumberString(amount:Number):String 7 | { 8 | var str:String = ""; 9 | for (var i:int = 0; i < amount; i++) 10 | str += String.fromCharCode(Math.round(Math.random() * (57 - 48)) + 48); 11 | return str; 12 | } 13 | } -------------------------------------------------------------------------------- /src/utils/string/randomSequence.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | import utils.number.randomIntegerWithinRange; 4 | 5 | /** 6 | * Get random sentence. 7 | * @param maxLength Max chars 8 | * @param minLength Min chars 9 | * @return Random sentence 10 | * @author Vaclav Vancura (http://vancura.org, http://twitter.com/vancura) 11 | */ 12 | public function randomSequence(maxLength:uint = 50, minLength:uint = 10):String { 13 | return randomCharacters(randomIntegerWithinRange(minLength, maxLength), " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/utils/string/randomSpecialCharacters.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Generate a set of random Special and Number characters. 5 | */ 6 | public function randomSpecialCharacters(amount:Number):String 7 | { 8 | var str:String = ""; 9 | for (var i:int = 0; i < amount; i++) 10 | str += String.fromCharCode(Math.round(Math.random() * (64 - 33)) + 33); 11 | return str; 12 | } 13 | } -------------------------------------------------------------------------------- /src/utils/string/remove.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Removes all instances of the remove string in the input string. 5 | * 6 | * @param input The string that will be checked for instances of remove 7 | * string 8 | * 9 | * @param remove The string that will be removed from the input string. 10 | * 11 | * @returns A String with the remove string removed. 12 | * 13 | * @langversion ActionScript 3.0 14 | * @playerversion Flash 9.0 15 | * @tiptext 16 | */ 17 | public function remove(input:String, remove:String):String 18 | { 19 | return replace(input, remove, ""); 20 | } 21 | } -------------------------------------------------------------------------------- /src/utils/string/removeExtraWhitespace.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Removes extraneous whitespace (extra spaces, tabs, line breaks, etc) from the specified String. 7 | * @param value String whose extraneous whitespace will be removed 8 | * @returns Output String 9 | */ 10 | public function removeExtraWhitespace(value:String):String { 11 | var out:String = ""; 12 | 13 | if(value) { 14 | var str:String = trim(value); 15 | 16 | out = str.replace(/\s+/g, " "); 17 | } 18 | 19 | return out; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/utils/string/removeSpaces.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Remove spaces from string. 5 | * @param str (String) 6 | * @return String 7 | */ 8 | public function removeSpaces(str:String):String 9 | { 10 | return replace(str, " ", ""); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /src/utils/string/removeTabs.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Remove tabs from string. 5 | */ 6 | public function removeTabs(str:String):String 7 | { 8 | return replace(str, " ", ""); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /src/utils/string/repeat.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | public function repeat(n:uint, str:String = " "):String { 6 | return new Array(n + 1).join(str); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/utils/string/reverse.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Returns the specified String in reverse character order. 7 | * @param value String that will be reversed 8 | * @returns Output String 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function reverse(value:String):String { 14 | var out:String = ""; 15 | 16 | if(value) { 17 | out = value.split("").reverse().join(""); 18 | } 19 | 20 | return out; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/utils/string/reverseWords.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Returns the specified String in reverse word order. 7 | * @param value String that will be reversed 8 | * @returns Output String 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function reverseWords(value:String):String { 14 | var out:String = ""; 15 | 16 | if(value) { 17 | out = value.split(/\s+/).reverse().join(""); 18 | } 19 | 20 | return out; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/utils/string/rtrim.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Removes whitespace from the end of the specified string. 7 | * 8 | * @param value The String whose ending whitespace will will be removed. 9 | * 10 | * @returns A String with whitespace removed from the end 11 | * 12 | * @langversion ActionScript 3.0 13 | * @playerversion Flash 9.0 14 | * @tiptext 15 | */ 16 | public function rtrim(value:String):String { 17 | var out:String = ""; 18 | 19 | if(value) { 20 | out = value.replace(/\s+$/, ""); 21 | } 22 | 23 | return out; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/utils/string/sanitizeNull.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Sanitizenull
strings for display purposes. 5 | */ 6 | public function sanitizeNull(str:String):String 7 | { 8 | return (str == null || str == "null") ? "" : str; 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/string/search.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Search for key in string. 5 | */ 6 | public function search(str:String, key:String, caseSensitive:Boolean = true):Boolean 7 | { 8 | if (!caseSensitive) 9 | { 10 | str = str.toUpperCase(); 11 | key = key.toUpperCase(); 12 | } 13 | return (str.indexOf(key) <= -1) ? false : true; 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/string/slashUnsafeChars.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * @private 5 | * @param chars 6 | * @return 7 | */ 8 | public function slashUnsafeChars(chars:String):String 9 | { 10 | var unsafeChar:String; 11 | var m:uint = constants.REGEX_UNSAFE_CHARS.length; 12 | 13 | for (var i:uint = 0; i < m; ++i) 14 | { 15 | unsafeChar = constants.REGEX_UNSAFE_CHARS.substr(i, 1); 16 | 17 | if (chars.indexOf(unsafeChar) != -1) 18 | chars = chars.replace(unsafeChar, "\\" + unsafeChar); 19 | } 20 | 21 | return chars; 22 | } 23 | } -------------------------------------------------------------------------------- /src/utils/string/stringHasValue.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Specifies whether the specified string is either non-null, or contains 5 | * characters (i.e. length is greater that 0) 6 | * 7 | * @param s The string which is being checked for a value 8 | * 9 | * @langversion ActionScript 3.0 10 | * @playerversion Flash 9.0 11 | * @tiptext 12 | */ 13 | public function stringHasValue(s:String):Boolean 14 | { 15 | return (s != null && s.length > 0); 16 | } 17 | } -------------------------------------------------------------------------------- /src/utils/string/stripTags.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Strip HTML markup tags. 5 | */ 6 | public function stripTags(str:String):String 7 | { 8 | var s:Array = new Array(); 9 | var c:Array = new Array(); 10 | for (var i:int = 0; i < str.length; i++) 11 | { 12 | if (str.charAt(i) == "<") 13 | { 14 | s.push(i); 15 | } 16 | else if (str.charAt(i) == ">") 17 | { 18 | c.push(i); 19 | } 20 | } 21 | var o:String = str.substring(0, s[0]); 22 | for (var j:int = 0; j < c.length; j++) 23 | { 24 | o += str.substring(c[j] + 1, s[j + 1]); 25 | } 26 | return o; 27 | } 28 | } -------------------------------------------------------------------------------- /src/utils/string/toDoubleQuote.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Convert single quotes to double quotes. 5 | */ 6 | public function toDoubleQuote(str:String):String 7 | { 8 | var sq:String = "'"; 9 | var dq:String = String.fromCharCode(34); 10 | return str.split(sq).join(dq); 11 | } 12 | } -------------------------------------------------------------------------------- /src/utils/string/toNumeric.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Remove all formatting and return cleaned numbers from string. 5 | * @example6 | * StringUtils.toNumeric("123-123-1234"); // returns 1221231234 7 | * 8 | */ 9 | public function toNumeric(str:String):String 10 | { 11 | var len:Number = str.length; 12 | var result:String = ""; 13 | for (var i:int = 0; i < len; i++) 14 | { 15 | var code:Number = str.charCodeAt(i); 16 | if (code >= 48 && code <= 57) 17 | { 18 | result += str.substr(i, 1); 19 | } 20 | } 21 | return result; 22 | } 23 | } -------------------------------------------------------------------------------- /src/utils/string/toSingleQuote.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Convert double quotes to single quotes. 5 | */ 6 | public function toSingleQuote(str:String):String 7 | { 8 | var sq:String = "'"; 9 | var dq:String = String.fromCharCode(34); 10 | return str.split(dq).join(sq); 11 | } 12 | } -------------------------------------------------------------------------------- /src/utils/string/toTitleCase.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Transforms source String to per word capitalization. 5 | */ 6 | public function toTitleCase(str:String):String 7 | { 8 | var lstr:String = str.toLowerCase(); 9 | return lstr.replace(/\b([a-z])/g, function($0:*):* 10 | { 11 | return $0.toUpperCase(); 12 | }); 13 | } 14 | } -------------------------------------------------------------------------------- /src/utils/string/trim.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Removes whitespace from the front and the end of the specified 7 | * string. 8 | * 9 | * @param value The String whose beginning and ending whitespace will 10 | * will be removed. 11 | * 12 | * @returns A String with whitespace removed from the begining and end 13 | * 14 | * @langversion ActionScript 3.0 15 | * @playerversion Flash 9.0 16 | * @tiptext 17 | */ 18 | public function trim(value:String):String { 19 | var out:String = ""; 20 | 21 | if(value) { 22 | out = value.replace(/^\s+|\s+$/g, ""); 23 | } 24 | 25 | return out; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/utils/string/trimCamel.as: -------------------------------------------------------------------------------- 1 | package utils.string 2 | { 3 | /** 4 | * Trim spaces and camel notate String. 5 | */ 6 | public function trimCamel(str:String = null):String 7 | { 8 | str = (!str) ? "" : str; 9 | var o:String = new String(); 10 | for (var i:int = 0; i < str.length; i++) 11 | { 12 | if (str.charAt(i) != " ") 13 | { 14 | if (justPassedSpace) 15 | { 16 | o += str.charAt(i).toUpperCase(); 17 | justPassedSpace = false; 18 | } 19 | else 20 | { 21 | o += str.charAt(i).toLowerCase(); 22 | } 23 | } 24 | else 25 | { 26 | var justPassedSpace:Boolean = true; 27 | } 28 | } 29 | return o; 30 | } 31 | } -------------------------------------------------------------------------------- /src/utils/string/wordCount.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Determines the number of words in a String. 7 | * @param value Input String 8 | * @returns Number of words in a String 9 | * @author Aaron Clinger 10 | * @author Shane McCartney 11 | * @author David Nelson 12 | */ 13 | public function wordCount(value:String):uint { 14 | var out:uint = 0; 15 | 16 | if(value) { 17 | out = value.match(/\b\w+\b/g).length; 18 | } 19 | 20 | return out; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/utils/string/xtrim.as: -------------------------------------------------------------------------------- 1 | package utils.string { 2 | 3 | 4 | 5 | /** 6 | * Extreme Trim: remove whitespace, line feeds, carriage returns from string 7 | */ 8 | public function xtrim(str:String = null):String { 9 | str = (!str) ? "" : str; 10 | 11 | var o:String = new String(); 12 | var TAB:Number = 9; 13 | var LINEFEED:Number = 10; 14 | var CARRIAGE:Number = 13; 15 | var SPACE:Number = 32; 16 | 17 | for(var i:int = 0; i < str.length; i++) { 18 | if(str.charCodeAt(i) != SPACE && str.charCodeAt(i) != CARRIAGE && str.charCodeAt(i) != LINEFEED && str.charCodeAt(i) != TAB) { 19 | o += str.charAt(i); 20 | } 21 | } 22 | 23 | return o; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/utils/textField/hideFields.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | 5 | /** 6 | * Hide aTextField
orTextField
's from display (visible false, alpha 0). 7 | * @see #reveal 8 | */ 9 | public function hideFields(... args):void 10 | { 11 | for (var i:int = 0; i < args.length; i++) 12 | { 13 | if (args[i] is TextField) 14 | { 15 | args[i].alpha = 0; 16 | args[i].visible = false; 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/textField/revealFields.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | 5 | /** 6 | * Reveal aTextField
orTextField
's (visible true, alpha 1) 7 | * @see #hide 8 | */ 9 | public function revealFields(... args):void 10 | { 11 | for (var i:int = 0; i < args.length; i++) 12 | { 13 | if (args[i] is TextField) 14 | { 15 | args[i].alpha = 1; 16 | args[i].visible = true; 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/textField/setStyledText.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.StyleSheet; 4 | import flash.text.TextField; 5 | 6 | /** 7 | * Apply aStyleSheet
to aTextField
& set its contents. 8 | * 9 | * @param tfTextField
to display. 10 | * @param str of text to apply. 11 | * @param stylesheet to apply to theTextField
's (Default:App.css
). 12 | * 13 | * @see sekati.core.App#css 14 | */ 15 | public function setStyledText(tf:TextField, str:String, stylesheet:StyleSheet = null):void 16 | { 17 | styleFields(tf, stylesheet); 18 | tf.htmlText = str; 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/textField/setTextColor.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | 5 | /** 6 | * Set theTextField
color formatting. 7 | */ 8 | public function setTextColor(tf:TextField, color:uint, backgroundColor:uint, borderColor:uint):void 9 | { 10 | tf.textColor = color; 11 | tf.background = true; 12 | tf.backgroundColor = backgroundColor; 13 | tf.border = true; 14 | tf.borderColor = borderColor; 15 | } 16 | } -------------------------------------------------------------------------------- /src/utils/textField/setTextFont.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | import flash.text.TextFormat; 5 | 6 | /** 7 | * Set theTextField
font formatting. 8 | */ 9 | public function setTextFont(tf:TextField, fontName:String, fontSize:Number, isEmbedFont:Boolean = false, isBold:Boolean = false, isItalic:Boolean = false, isUnderline:Boolean = false):void 10 | { 11 | var fmt:TextFormat = tf.getTextFormat(); 12 | fmt.font = fontName; 13 | fmt.size = fontSize; 14 | fmt.italic = isItalic; 15 | fmt.bold = isBold; 16 | fmt.underline = isUnderline; 17 | tf.embedFonts = isEmbedFont; 18 | tf.setTextFormat(fmt); 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/textField/setTextLeading.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | import flash.text.TextFormat; 5 | 6 | /** 7 | * Set theTextField
leading formatting. 8 | */ 9 | public function setTextLeading(tf:TextField, space:Number = 0):void 10 | { 11 | var fmt:TextFormat = tf.getTextFormat(); 12 | fmt.leading = space; 13 | tf.setTextFormat(fmt); 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/textField/setTextLetterSpacing.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | import flash.text.TextFormat; 5 | 6 | /** 7 | * Set theTextField
letter spacing formatting. 8 | */ 9 | public function setTextLetterSpacing(tf:TextField, spacing:Number = 0):void 10 | { 11 | var fmt:TextFormat = tf.getTextFormat(); 12 | fmt.letterSpacing = spacing; 13 | tf.setTextFormat(fmt); 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/textField/setTextSpaceWidth.as: -------------------------------------------------------------------------------- 1 | package utils.textField 2 | { 3 | import flash.text.TextField; 4 | import flash.text.TextFormat; 5 | 6 | /** 7 | * Set theTextField
's width for space characters. 8 | */ 9 | public function setTextSpaceWidth(tf:TextField, space:Number = 1):void 10 | { 11 | var fmt:TextFormat = new TextFormat(); 12 | fmt.letterSpacing = space; 13 | var i:int = 0; 14 | while (tf.text.indexOf(" ", i) > -1) 15 | { 16 | var index:int = tf.text.indexOf(" ", i); 17 | tf.setTextFormat(fmt, index, index + 1); 18 | i = index + 1; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/utils/type/PACKAGE_CLASS_SEPARATOR.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | [ExcludeClass] 4 | const PACKAGE_CLASS_SEPARATOR:String = "::"; 5 | } -------------------------------------------------------------------------------- /src/utils/type/convertFullyQualifiedName.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | /** 4 | * Converts the double colon (::) in a fully qualified class name to a dot (.) 5 | */ 6 | public function convertFullyQualifiedName(className:String):String 7 | { 8 | return className.replace(PACKAGE_CLASS_SEPARATOR, "."); 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/type/describeInheritance.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | /** 4 | * Targeted reflection describing an object's inheritance, including 5 | * extended classes and implemented interfaces. 6 | * 7 | * @param value The object or class to introspect. 8 | * 9 | * @return A list of XML inheritance descriptions. 10 | */ 11 | public function describeInheritance(value:Object):XMLList 12 | { 13 | return describeType(value).factory.*.(localName() == "extendsClass" || localName() == "implementsInterface"); 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/type/describeMethods.as: -------------------------------------------------------------------------------- 1 | package utils.type { 2 | 3 | 4 | 5 | /** 6 | * Targeted reflection describing an object's methods. 7 | * @param value The object or class to introspect. 8 | * @param metadataType Optional filter to return only those 9 | * method descriptions containing the 10 | * specified metadata. 11 | * @return A list of XML method descriptions. 12 | */ 13 | public function describeMethods(value:Object, metadataType:String = null):XMLList { 14 | var methods:XMLList = describeType(value).factory.method; 15 | 16 | return (metadataType == null) ? methods : methods.(child("metadata").(@name == metadataType).length() > 0); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/utils/type/getClassByName.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.utils.getDefinitionByName; 4 | 5 | /** 6 | * Get a class by its fully-qualified name 7 | * @param className Fully-qualified name of the class 8 | * @return The class with the given name or null if none exists 9 | * @author Jackson Dunstan 10 | */ 11 | public function getClassByName(className:String):Class 12 | { 13 | try 14 | { 15 | return Class(getDefinitionByName(className)); 16 | } 17 | catch (refErr:ReferenceError) 18 | { 19 | return null; 20 | } 21 | catch (typeErr:TypeError) 22 | { 23 | return null; 24 | } 25 | 26 | return null; 27 | } 28 | } -------------------------------------------------------------------------------- /src/utils/type/getClassName.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.utils.getQualifiedClassName; 4 | 5 | /** 6 | * Returns the exact class name, without package or path. 7 | * 8 | * @param value The object for which the class name is desired. 9 | * Any ActionScript value may be passed including 10 | * all ActionScript types, object instances, 11 | * primitive types such as uint, and class objects. 12 | */ 13 | public function getClassName(value:Object):String 14 | { 15 | return getQualifiedClassName(value).split("::").pop(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/utils/type/getDisplayObjectClass.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.display.DisplayObject; 4 | import flash.utils.getQualifiedClassName; 5 | 6 | /** 7 | * Get the class of a display object 8 | * @param obj Object to get the class of 9 | * @return The class of the given object or null if the class cannot be 10 | * determined 11 | * @author Jackson Dunstan 12 | */ 13 | public function getDisplayObjectClass(obj:DisplayObject):Class 14 | { 15 | try 16 | { 17 | return Class(obj.loaderInfo.applicationDomain.getDefinition(getQualifiedClassName(obj))); 18 | } 19 | catch (refErr:ReferenceError) 20 | { 21 | return null; 22 | } 23 | catch (typeErr:TypeError) 24 | { 25 | return null; 26 | } 27 | 28 | return null; 29 | } 30 | } -------------------------------------------------------------------------------- /src/utils/type/getFullyQualifiedName.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.utils.getQualifiedClassName; 4 | 5 | /** 6 | * Returns the fully qualified name of the given class. 7 | * 8 | * @param clazz the class to get the name from 9 | * @param replaceColons whether the double colons "::" should be replaced by a dot "." 10 | * the default is false 11 | * 12 | * @return the fully qualified name of the class 13 | */ 14 | public function getFullyQualifiedName(clazz:Class, replaceColons:Boolean = false):String 15 | { 16 | var result:String = getQualifiedClassName(clazz); 17 | 18 | if (replaceColons) 19 | { 20 | result = convertFullyQualifiedName(result); 21 | } 22 | return result; 23 | } 24 | } -------------------------------------------------------------------------------- /src/utils/type/getFullyQualifiedSuperClassname.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.utils.getQualifiedSuperclassName; 4 | 5 | /** 6 | * Returns the fully qualified name of the given class' superclass. 7 | * 8 | * @param clazz the class to get its superclass' name from 9 | * @param replaceColons whether the double colons "::" should be replaced by a dot "." 10 | * the default is false 11 | * 12 | * @return the fully qualified name of the class' superclass 13 | */ 14 | public function getFullyQualifiedSuperClassname(clazz:Class, replaceColons:Boolean = false):String 15 | { 16 | var result:String = getQualifiedSuperclassName(clazz); 17 | 18 | if (replaceColons) 19 | { 20 | result = convertFullyQualifiedName(result); 21 | } 22 | return result; 23 | } 24 | } -------------------------------------------------------------------------------- /src/utils/type/getName.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | /** 4 | * Returns the name of the given class. 5 | * 6 | * @param clazz the class to get the name from 7 | * 8 | * @return the name of the class 9 | */ 10 | public function getName(clazz:Class):String 11 | { 12 | return getNameFromFullyQualifiedName(getFullyQualifiedName(clazz)); 13 | } 14 | } -------------------------------------------------------------------------------- /src/utils/type/getSuperClassName.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | /** 4 | * Returns the name of the given class' superclass. 5 | * 6 | * @param clazz the class to get the name of its superclass' from 7 | * 8 | * @return the name of the class' superclass 9 | */ 10 | public function getSuperClassName(clazz:Class):String 11 | { 12 | var fullyQualifiedName:String = getFullyQualifiedSuperClassname(clazz); 13 | var index:int = fullyQualifiedName.indexOf(PACKAGE_CLASS_SEPARATOR) + PACKAGE_CLASS_SEPARATOR.length; 14 | return fullyQualifiedName.substring(index, fullyQualifiedName.length); 15 | } 16 | } -------------------------------------------------------------------------------- /src/utils/type/getType.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.utils.Proxy; 4 | import flash.utils.getDefinitionByName; 5 | import flash.utils.getQualifiedClassName; 6 | 7 | public function getType(value:Object):Class 8 | { 9 | if (value is Class) 10 | { 11 | return value as Class; 12 | } 13 | else if (value is Proxy) 14 | { 15 | return getDefinitionByName(getQualifiedClassName(value)) as Class; 16 | } 17 | else 18 | { 19 | return value.constructor as Class; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/utils/type/isInterface.as: -------------------------------------------------------------------------------- 1 | package utils.type { 2 | /** 3 | * Returns whether the passed in Class object is an interface. 4 | * 5 | * @param clazz the class to check 6 | * @return true if the clazz is an interface; false if not 7 | */ 8 | public function isInterface(clazz:Class):Boolean { 9 | return (clazz == Object) ? false : (describeType(clazz).factory.extendsClass.length() == 0); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/utils/type/typeCache.as: -------------------------------------------------------------------------------- 1 | package utils.type 2 | { 3 | import flash.utils.Dictionary; 4 | 5 | // global cache improves reflection performance significantly 6 | public var typeCache:Dictionary = new Dictionary(); 7 | } -------------------------------------------------------------------------------- /src/utils/validation/US_STATE_ABBREVIATIONS.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | public const US_STATE_ABBREVIATIONS:Array = [ 4 | 'ak', 'al', 'ar', 'az', 'ca', 'co', 'ct', 'dc', 'de', 'fl', 5 | 'ga', 'hi', 'ia', 'id', 'il', 'in', 'ks', 'ky', 'la', 'ma', 6 | 'md', 'me', 'mi', 'mn', 'mo', 'ms', 'mt', 'nb', 'nc', 'nd', 7 | 'nh', 'nj', 'nm', 'nv', 'ny', 'oh', 'ok', 'or', 'pa', 'ri', 8 | 'sc', 'sd', 'tn', 'tx', 'ut', 'va', 'vt', 'wa', 'wi', 'wv', 9 | 'wy']; 10 | } -------------------------------------------------------------------------------- /src/utils/validation/isBlank.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | import utils.string.trim; 4 | 5 | /** 6 | * Validate if a strings contents are blank after a safety trim is performed. 7 | */ 8 | public function isBlank(s:String = null):Boolean 9 | { 10 | var str:String = trim(s); 11 | var i:int = 0; 12 | if (str.length == 0) 13 | { 14 | return true; 15 | } 16 | while (i < str.length) 17 | { 18 | if (str.charCodeAt(0) != 32) 19 | { 20 | return false; 21 | } 22 | i++; 23 | } 24 | return true; 25 | } 26 | } -------------------------------------------------------------------------------- /src/utils/validation/isEmail.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | Determines if String is a valid email address. 5 | 6 | @param email: String to verify as email. 7 | @return Returnstrue
if String is a valid email; otherwisefalse
. 8 | @see http://www.regular-expressions.info/email.html Read more about the regular expression used by this method. 9 | */ 10 | public function isEmail(email:String):Boolean 11 | { 12 | var pattern:RegExp = /^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i; 13 | return email.match(pattern) != null; 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/validation/isNumeric.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | * Validate if a string is composed entirely of numbers. 5 | */ 6 | public function isNumeric(str:String):Boolean 7 | { 8 | if (str == null) 9 | { 10 | return false; 11 | } 12 | var regx:RegExp = /^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/; 13 | return regx.test(str); 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/validation/isPOBox.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | * Check if address is a Post Office Box 5 | */ 6 | public function isPOBox(address:String):Boolean 7 | { 8 | var look:Array = [ "PO ", "P O", "P.O", "P. O", "p o", "p.o", "p. o", "Box", "Post Office", "post office" ]; 9 | var len:Number = look.length; 10 | for (var i:int = 0; i < len; i++) 11 | { 12 | if (address.indexOf(look[i]) != -1) 13 | { 14 | return true; 15 | } 16 | } 17 | return false; 18 | } 19 | } -------------------------------------------------------------------------------- /src/utils/validation/isURL.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | * Validate as "http://" or "https://". 5 | */ 6 | public function isURL(str:String):Boolean 7 | { 8 | return (str.substring(0, 7) == "http://" || str.substring(0, 8) == "https://"); 9 | } 10 | } -------------------------------------------------------------------------------- /src/utils/validation/isUSAStateAbbreviation.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | import utils.array.contains; 4 | 5 | /** 6 | Determines if String is a valid USA state abbreviation. 7 | 8 | @param state: String to verify as two letter state abbreviation (includes DC). 9 | @return Returnstrue
if String is a state abbreviation; otherwisefalse
. 10 | */ 11 | public function isUSAStateAbbreviation(state:String):Boolean 12 | { 13 | return contains(US_STATE_ABBREVIATIONS, state.toLowerCase()) == 1; 14 | } 15 | } -------------------------------------------------------------------------------- /src/utils/validation/isValidEmailAddress.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | * Validate a string as a valid email address. 5 | */ 6 | public function isValidEmailAddress(str:String):Boolean 7 | { 8 | var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i; 9 | return emailExpression.test(str); 10 | } 11 | } -------------------------------------------------------------------------------- /src/utils/validation/isValidExpirationDate.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | * Validate a credit card's expiration date. 5 | * @example6 | * var isValidDate:Boolean = CreditCardValidator.isValidExDate( 11, 2010 ); 7 | * 8 | */ 9 | public function isValidExpirationDate(month:int, year:int):Boolean 10 | { 11 | var d:Date = new Date(); 12 | var currentMonth:int = d.getMonth() + 1; 13 | var currentYear:int = d.getFullYear(); 14 | if ((year > currentYear) || (year == currentYear && month >= currentMonth)) 15 | { 16 | return true; 17 | } 18 | return false; 19 | } 20 | } -------------------------------------------------------------------------------- /src/utils/validation/isValidPhoneNumber.as: -------------------------------------------------------------------------------- 1 | package utils.validation 2 | { 3 | /** 4 | * Validate a string as a phone number. 5 | */ 6 | public function isValidPhoneNumber(str:String):Boolean 7 | { 8 | var phoneExpression:RegExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/i; 9 | return phoneExpression.test(str); 10 | } 11 | } -------------------------------------------------------------------------------- /src/utils/xml/getNextSibling.as: -------------------------------------------------------------------------------- 1 | package utils.xml 2 | { 3 | /** 4 | * Returns the next sibling of the specified node relative to the node's parent. 5 | * 6 | * @param x The node whose next sibling will be returned. 7 | * 8 | * @return The next sibling of the node. null if the node does not have 9 | * a sibling after it, or if the node has no parent. 10 | * 11 | * @langversion ActionScript 3.0 12 | * @playerversion Flash 9.0 13 | */ 14 | public function getNextSibling(x:XML):XML 15 | { 16 | return getSiblingByIndex(x, 1); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/xml/getPreviousSibling.as: -------------------------------------------------------------------------------- 1 | package utils.xml 2 | { 3 | /** 4 | * Returns the sibling before the specified node relative to the node's parent. 5 | * 6 | * @param x The node whose sibling before it will be returned. 7 | * 8 | * @return The sibling before the node. null if the node does not have 9 | * a sibling before it, or if the node has no parent. 10 | * 11 | * @langversion ActionScript 3.0 12 | * @playerversion Flash 9.0 13 | */ 14 | public function getPreviousSibling(x:XML):XML 15 | { 16 | return getSiblingByIndex(x, -1); 17 | } 18 | } -------------------------------------------------------------------------------- /src/utils/xml/isValidXML.as: -------------------------------------------------------------------------------- 1 | package utils.xml 2 | { 3 | /** 4 | * Checks whether the specified string is valid and well formed XML. 5 | * 6 | * @param data The string that is being checked to see if it is valid XML. 7 | * 8 | * @return A Boolean value indicating whether the specified string is 9 | * valid XML. 10 | * 11 | * @langversion ActionScript 3.0 12 | * @playerversion Flash 9.0 13 | */ 14 | public function isValidXML(data:String):Boolean 15 | { 16 | var xml:XML; 17 | 18 | try 19 | { 20 | xml = new XML(data); 21 | } 22 | catch (e:Error) 23 | { 24 | return false; 25 | } 26 | 27 | return xml.nodeKind() == XMLConstants.ELEMENT; 28 | } 29 | } -------------------------------------------------------------------------------- /test/utils/date/calendar/CalendarTests.as: -------------------------------------------------------------------------------- 1 | /** 2 | * User: John Lindquist 3 | * Date: 3/16/11 4 | * Time: 11:14 AM 5 | */ 6 | package utils.date.calendar 7 | { 8 | 9 | import org.hamcrest.assertThat; 10 | 11 | import org.hamcrest.object.equalTo; 12 | 13 | import utils.date.Calendar; 14 | 15 | public class CalendarTests 16 | { 17 | [Test] 18 | public function now_should_be_the_current_time():void 19 | { 20 | var calendar:Calendar = new Calendar(); 21 | 22 | assertThat(calendar.now.toString(), equalTo(new Date().toString())); 23 | } 24 | 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /test/utils/dictionary/CircularDictionaryTest.as: -------------------------------------------------------------------------------- 1 | package utils.dictionary 2 | { 3 | import flexunit.framework.Assert; 4 | 5 | import utils.dictionary.CircularDictionary; 6 | 7 | public class CircularDictionaryTest 8 | { 9 | [Test] 10 | public function testAddAndRemovePair():void { 11 | var a:Object = {foo:"bar"}; 12 | var b:int = 42; 13 | 14 | var dict:CircularDictionary = new CircularDictionary(); 15 | dict.addPair(a,b); 16 | Assert.assertEquals(a, dict.getCounterpartTo(b)); 17 | Assert.assertEquals(b, dict.getCounterpartTo(a)); 18 | 19 | var result:* = dict.removePair(a); 20 | Assert.assertUndefined(dict.getCounterpartTo(a), dict.getCounterpartTo(b)); 21 | Assert.assertEquals(result, b); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /test/utils/geom/CartesianToPolarCoordinatesTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: Sep 30, 2010 5 | * Time: 11:50:50 AM 6 | */ 7 | package utils.geom 8 | { 9 | 10 | import org.flexunit.asserts.assertTrue; 11 | import utils.geom.cartesianToPolarCoordinates; 12 | 13 | public class CartesianToPolarCoordinatesTest 14 | { 15 | 16 | [Before] 17 | public function setup():void 18 | { 19 | 20 | } 21 | 22 | [Test] 23 | public function CartesianToPolarCoordinatesReturnsProperCoords():void 24 | { 25 | 26 | var polarCoord:Array = cartesianToPolarCoordinates(3, 4); 27 | 28 | assertTrue(polarCoord[0] == 5 && polarCoord[1] == 53.13010235415598) 29 | 30 | } 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /test/utils/number/ClampTest.as: -------------------------------------------------------------------------------- 1 | package utils.number 2 | { 3 | import flexunit.framework.Assert; 4 | 5 | import utils.number.clamp; 6 | 7 | public class ClampTest 8 | { 9 | [Test] 10 | public function testClamp():void { 11 | var low:int = 0; 12 | var high:int = 100; 13 | 14 | Assert.assertEquals("Values between low and high are passed thru.", clamp(50, low, high), 50); 15 | Assert.assertEquals("Values lower than low value are limited to the low value.", clamp(low - 100, low, high), low); 16 | Assert.assertEquals("Values higher than the high value are limited to the high value.", clamp(high + 100, low, high), high); 17 | Assert.assertEquals("If any values are NaN, return NaN.", clamp(5, NaN, high), NaN); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /test/utils/object/MergeTest.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | import org.hamcrest.assertThat; 4 | import org.hamcrest.object.hasProperties; 5 | 6 | public class MergeTest 7 | { 8 | [Test] 9 | public function copiesEnumerablePropertiesAndValuesFromSourceToTarget():void 10 | { 11 | var source:Object = { a: 1, d: 4 }; 12 | var target:Object = { a: 0, b: 2, c: 3 } 13 | 14 | assertThat(merge(target, source), hasProperties({ a: 1, b: 2, c: 3, d: 4 })); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /test/utils/object/containsTest.as: -------------------------------------------------------------------------------- 1 | package utils.object 2 | { 3 | import flexunit.framework.Assert; 4 | import utils.object.contains; 5 | 6 | public class ContainsTest 7 | { 8 | [Test] 9 | public function testContains():void { 10 | var o:Object = {foo:"bar", baz:42}; 11 | var p:Object = {foo:o}; 12 | 13 | Assert.assertTrue("Object contains 'bar'", contains(o, "bar")); 14 | Assert.assertFalse("Doesn't check property names", contains(o, "foo")); 15 | Assert.assertTrue("Object contains other objects", contains(p, o)); 16 | } 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /test/utils/validation/encodeCreditCardNumberTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 3:07 PM 6 | */ 7 | package utils.validation { 8 | public class EncodeCreditCardNumberTest { 9 | public function EncodeCreditCardNumberTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/getCreditCardProviderTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 1:26 PM 6 | */ 7 | package utils.validation { 8 | public class GetCreditCardProviderTest { 9 | public function GetCreditCardProviderTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/isBlankTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 11:48 AM 6 | */ 7 | package utils.validation { 8 | public class IsBlankTest { 9 | public function IsBlankTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/isCreditCardTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 11:44 AM 6 | */ 7 | package utils.validation { 8 | public class IsCreditCardTest { 9 | public function IsCreditCardTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/isEmailTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 11:39 AM 6 | */ 7 | package utils.validation { 8 | public class IsEmailTest { 9 | public function IsEmailTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/isNumericTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 11:37 AM 6 | */ 7 | package utils.validation { 8 | public class IsNumericTest { 9 | public function IsNumericTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/isPOBoxTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 11:35 AM 6 | */ 7 | package utils.validation { 8 | public class IsPOBoxTest { 9 | public function IsPOBoxTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/validation/isUrlTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/24/11 5 | * Time: 11:29 AM 6 | */ 7 | package utils.validation { 8 | public class IsUrlTest { 9 | public function IsUrlTest() { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/utils/xml/GetNextSiblingTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/3/11 5 | * Time: 2:28 PM 6 | */ 7 | package utils.xml { 8 | import org.hamcrest.assertThat; 9 | import org.hamcrest.object.equalTo; 10 | 11 | public class GetNextSiblingTest { 12 | 13 | [Test] 14 | public function requestedIndexShouldReturnNextNode() : void { 15 | 16 | var x:XML = 17 |18 | 22 | 23 | var sibling:* = getNextSibling(x.stuff[1]); 24 | 25 | assertThat(sibling, equalTo(x.stuff[2])); 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/utils/xml/GetPreviousSiblingTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/3/11 5 | * Time: 2:08 PM 6 | */ 7 | package utils.xml { 8 | import org.hamcrest.assertThat; 9 | import org.hamcrest.object.equalTo; 10 | 11 | public class GetPreviousSiblingTest { 12 | 13 | [Test] 14 | public function callShouldReturnPreviousNode() : void { 15 | 16 | var x:XML = 17 |value1 19 |value2 20 |value3 21 |18 | 22 | 23 | var sibling:* = getPreviousSibling(x.stuff[2]); 24 | 25 | assertThat(sibling, equalTo(x.stuff[1])); 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/utils/xml/GetSiblingByIndexTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/3/11 5 | * Time: 12:04 PM 6 | */ 7 | package utils.xml { 8 | import org.hamcrest.assertThat; 9 | import org.hamcrest.object.equalTo; 10 | 11 | public class GetSiblingByIndexTest { 12 | 13 | [Test] 14 | public function requestedIndexShouldReturnProperNode() : void { 15 | 16 | var x:XML = 17 |value1 19 |value2 20 |value3 21 |18 | 22 | 23 | var sibling:* = getSiblingByIndex(x.stuff[2], -1); 24 | 25 | assertThat(sibling, equalTo(x.stuff[1])) 26 | 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/utils/xml/isValidXMLTest.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by IntelliJ IDEA. 3 | * User: Ian McLean 4 | * Date: 5/2/11 5 | * Time: 4:40 PM 6 | */ 7 | package utils.xml { 8 | import org.hamcrest.assertThat; 9 | import org.hamcrest.object.equalTo; 10 | 11 | public class IsValidXMLTest { 12 | 13 | [Test] 14 | public function validXMLShouldReturnTrue() : void { 15 | 16 | var s:String = "value1 19 |value2 20 |value3 21 |"; 17 | 18 | assertThat(isValidXML(s), equalTo(true)) 19 | 20 | } 21 | 22 | [Test] 23 | public function invalidXMLShouldReturnFalse() : void { 24 | 25 | 26 | var s:String = " "; 27 | 28 | assertThat(isValidXML(s), equalTo(false)) 29 | 30 | } 31 | } 32 | } 33 | --------------------------------------------------------------------------------