AS2 Array count values
AS2 Array count values
Actionscript port of array_count_values
In PHP there is a very useful function called array_count_values. It sorts an array by returning a 2 dimensional array consisting of non duplicate elements as keys, and values determined by how many times these elements appeared in the original array.
So, for example, an array [“red”,”green”,”blue”,”red”] would be converted into [“red” => 2, “green” =>1, “blue” => 1]. Duplicate elements are removed and the new array indicates how many times each, now unique value occurred in the array.
Unfortunately, Actionscript has no such function built in, so I made one. It is a modification of Senocular’s array.unique() prototype (which you can find in his Actionscript library), however rather than simply returning a unique array, it returns the 2 dimensional array mentioned above. // Read More
Splitting Strings
Splitting Strings
Split strings to an array of phrases
I was working on a project recently where I recieved a data feed and needed to split it into sections that would fit into a text box (ie. 200 characters at a time). The user would then click ‘more‘ and progress through the text in segments until they had read all of it.
I wrote this simple prototype, which splits a string into sections of a defined size (and optionally adds a postfix, ie. “…” to the end), and returns an array containing the segmented text. // Read More
Array search and replace
Array search and replace
Search and replace array items
Another find and replace prototype that might be useful for someone. Flash has some useful inbuilt functions like pop() which make life easier, but this prototype will search an array for a particular value and remove it, returning the new array. // Read More
String search and replace
String search and replace
Replace a string with another string
A useful prototype for running a ’search and replace’ on a string in Flash. Great, for example, when a database is spewing out rubbish string pre/post fixes, or HTML code that Flash doesn’t support. Im sure there is similar stuff out there but I hope it will be useful for someone none-the-less. // Read More