Flash Actionscript 3: Easily Jumble elements of an Array or String

Sometimes in Actionscript you need an easy way to jumble elements of an array or string, such as for a card/word game. I created this simple little as3 class that you can use for just that:

// Usage:
// yourNewString = Jumble.string(yourOldString);
// yourNewArray = Jumble.array(yourOldArray);

package com.frigidfish{

    public class Jumble {

        public function Jumble() {}

        public static function string(s:String):String {
            var a:Array = s.split("");
            var r:String = "";
            a = a.sort(randomize);
            for(var i=0;i<a.length;i++){
                r += a[i];
            return r;

        public static function array(a:Array):Array {
            a = a.sort(randomize);
            return a;

        private static function randomize(objA:Object, objB:Object):int {
            return Math.round(Math.random()*2)-1;


import com.frigidfish.Jumble;

var string:String = "abcdefghijklmnopqrstuvwxyz";
var array:Array = ["a","b","c","d","e","f","g","e"];


possible output:

This is a useful couple of tools.. Maybe you could add functions to return the output in different formats? Above all, have fun with Flash Actionscript 3!

flash and php – Send/Receive Variables from Actionscript 3 & PHP

Below is a class that I made that can be used to send a group of variables to a php script on a server and receive the results. I use this all the time when working between flash and php in my projects!

// FlashPHP Class by Rick Nuthman
// 8.28.09
// Constructor receives 2 arguments:
// url:String - The url to the PHP file
// flashVars:Object - An object that contains variables to be sent to the url
// The class dispatches 1 event called "ready" once the php transaction is complete.
// listen for this event. Once it's received you can access returned variabled from receievedVars.

package com.frigidfish{

    import flash.net.URLVariables;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequestMethod;
    import flash.events.EventDispatcher;
    import flash.events.Event;

    public class FlashPHP extends EventDispatcher {
        // Public Properties
        public var receivedVars:URLVariables;      
        // Private Properties
        private var url:String;    
        private var flashVars:Object;
        private var request:URLRequest;
        private var completeEvent:Event              = new Event("ready");
        private var variables:URLVariables           = new URLVariables();
        private var loader:URLLoader                 = new URLLoader();

        public function FlashPHP(url:String, flashVars:Object) {
            this.flashVars                      = flashVars;
            this.url                            = url+"?r="+ new Date().getTime();

        // Private Methods
        private function parseVariables() {
            for (var item in flashVars) {
                variables[item] = flashVars[item];             

        private function sendVariables() {
            request                                 = new URLRequest(url);
            request.method                          = URLRequestMethod.POST;
            request.data                            = variables;
            loader.dataFormat                       = URLLoaderDataFormat.VARIABLES;           
            loader.addEventListener(Event.COMPLETE, variablesAreLoaded);

        function variablesAreLoaded(event:Event) {
            receivedVars                            = new URLVariables(loader.data);

Here is an example of how to implement it:

import com.frigidfish.FlashPHP;
var score:String = "100";
var playerName:String = "Bobby";
var phpData:*;

var playerObject:Object = new Object();
playerObject.score = score;
playerObject.playerName = playerName;

var flashPHP:FlashPHP = new FlashPHP("http://www.yoursite.com/yourphp.php", playerObject);
flashPHP.addEventListener("ready", processPHPVars);

function processPHPVars(event:Event){
// put the object that php sends back into a var (in this case phpData)

phpData = event.target.receivedVars;

Of course it will be necessary to know what to do with the data on the PHP side… here is a simple script that receives that variables and sends back a simple response var called ‘success’:

$teamName = $_POST['playerName'];
$score = $_POST['score'];
// Here you would put any processing functions...

$success = "1";
$returnVars = array();
$returnVars['success'] = $success;
$returnString = http_build_query($returnVars);
echo $returnString;

Basically, this script does nothing with the variables that are collected, but as you can see, it just takes what is posted from flash and assigns it to php variables. Lastly, we create a new array to contain any vars that will be sent back to flash. This array is converted into a query string which is translated by FlashPHP into an object containing the variables by key names created in PHP.

I hope this makes sense, it’s actually quite easy to use! Don’t forget to wait for the FlashPHP “ready” event to trigger before attempting to access its receivedvars property. Feel free to ask any questions if anything doesn’t make sense 🙂

Download Example