I figured it might be nice to have a thread where people can post some useful AS code snippets for all to see. If you have some useful code, by all means post it in this thread and I will index it in this post ASAP. If you do post some code, please give a short description on how to use it. A sample would be nice too.
:mountie:
[SIZE=3]String[/SIZE]
strReplace - A function used for replacing portions of a string with a new one.
wordCount - Returns the amount of words in the argument.
is_str - Returns [FONT=Courier New][FONT=Verdana]true[/FONT] [/FONT]if the argument is a string, or can be used as a string.
autoFormat - All sentences are started with a capital, all "I"s are capitalised and sentences can be spaced.
[SIZE=3]Array[/SIZE]
arrIndexOf - A function used for finding the index of the first occurance of an object in an array.
arrLastIndexOf - A function used for finding the index of the last occurance of an object in an array.
remove - Removes the specified index element from an array.
shuffle - Randomises the contents of any array between the startIndex and endIndex indices.
[SIZE=3]MovieClip[/SIZE]
createClassMovieClip - A function used for creating empty movie clips with subclass association.
_brightness - Property for setting brightness of a movieclip (like in the IDE). Value range from -100% to 100%.
_recordframerate - Records the approximate frame rate.
fadeOut - Fades a movie clip out of the stage, based on the fade speed.
[SIZE=3]Number/Math[/SIZE]
numParity - A function that returns the parity of a number. In mathematics, parity refers to whether a number is odd or even.
factorial - A function that returns n! (factorial) from a positive integer or the amount of combinations possible from a set.
numDerive - A function for approximating the derivative of a function at a point.
numRoundTo - A function for rounding a decimal number to a precision.
addCommas - Converts the parameter to a string and formats the number value correctly with decmals where necessary.
ordinalise - Reads the numberparameter and converts it into an ordinalised String.
is_numeric - Returns [FONT=Courier New][FONT=Verdana]true[/FONT] [/FONT]if the argument is a number.
distanceBetween - Calculates the distance between 2 points.
[SIZE=3]Sound[/SIZE]
pause - Stops a playing sound at it’s current position and allows access to a variable [FONT=Courier New]newPosition[/FONT][FONT=Verdana] which enables the sound to resume at it’s last position.[/FONT]
[SIZE=3]Color[/SIZE]
setBrightness - Method for setting brightness of a Color object. Value range from -100% to 100%.
[SIZE=3]Object[/SIZE]
**[SIZE=3]_[/SIZE]**recordDownloadSpeed - Monitors how fast an Object is downloading
[SIZE=3]TextField[/SIZE]
getAction - Returns an the type of modification (paste or cut) done to a text field.
[SIZE=3]Drawing Methods[/SIZE]
drawStar - A function used to draw stars in a movie clip.
[SIZE=3]Miscellaneous[/SIZE]
verifyEmail - Reads the address parameter to a string and checks that it is compliant to the typical “valid” email standards of today.
alertPopup - This creates a nice looking draggable popup.
[SIZE=3]Classes[/SIZE]
com.Javascript.Request - URL query vars class.
com.centerObjects.centerEasing - Tells flash to keep content within a flash movie centered.
com.dragging.Dragger - This class is designed to move objects in a grid.
[SIZE=3]Code Snippets[/SIZE]
Custom ContextMenu - A script that hides the original right-click menu’s playback & zoom functions and allows you to add your own.
Accordian Component with Child List Components - This code creates an accordion component with 3 list components as its children.
Display Current Frame - A movieclip that you can place anywhere in your flash movie that will automatically display the current frame.