Archive | August, 2011

Simple data storage from Flash to ExpressionEngine

26 Aug

Am working in a great project at the time. The backend is my fav cms ExpressionEngine and I play with audio programming, mutitouch, and phidgets all day. Good times!

Just thought that I’d post some experiences in getting data from Flash to ExpressionEngine since I’ve spent some time on that. The initial idea was to use SafeCracker with EE. This works to some extent, but there are a couple hiccups. Mostly it’s because of the XID required to do safe forms and 302 redirects. Due to this, we had to find a another path. For anything more advanced, we’ll use AMFie (ActionScript Remoting for EE, developed by bjornbjorn) but for the simple stuff, we’ll just use the Metaweblogs API plugin that comes with EE. It’s simple, but it’s all you need to just save some text easily (Getting it out is super easy with a custom template).

I was a little puzzled that there were only AS1 and AS2 libraries for XMLRPC. If you know of an updated AS3 Metaweblog API for Flash, please post it in the comments. Documentation for the Metaweblog API was rather crappy since the main site is broken but I found a couple resources that helped me solve how the XML were supposed to look. If you want to see how it’s done, there’s code in the extended entry. This is no API, but it does show how to insert data. It’s the same for the other methods.

Here’s the code snippet I use with the Metaweblog API:

         * Stores the users progression
         * Uses the Metaweblog API module in ExpressionEngine
         * @param session_id The id returned from getSession();
         * @param key A key you define for use with your application
         * @param value A value for the key
        public static function saveContent( session_id:String, key:String, value:String ):void
            // The message that the MetaWeblog API wants
            var payload:String = "";
            payload += "";
            payload += "    metaWeblog.newPost";
            payload += "    ";
            payload += "        ";
            payload += "            2";                    // EE channel
            payload += "        

payload += "

"; payload += " myuser"; // EE user payload += "

payload += "

"; payload += " mypass"; // EE password payload += "

payload += "

"; payload += " "; payload += " "; // Struct with members per field payload += " "; payload += " title"; payload += " "+session_id+" - "+key+" - "+value+""; payload += " "; payload += " "; payload += " mt_excerpt"; payload += " "+session_id+""; payload += " "; payload += " "; payload += " description"; payload += " "+key+""; payload += " "; payload += " "; payload += " mt_text_more"; payload += " "+value+""; payload += " "; payload += " "; payload += " mt_keywords"; payload += " mt_keywords"; payload += " "; payload += " "; payload += " "; payload += "

payload += "

"; payload += " 1"; payload += "

payload += "

payload += "


var req:URLRequest = new URLRequest(""); // This value, you'll find on EE's metaweblog api module info page
req.method = URLRequestMethod.POST; = payload;

// Flash will add User-Agent and Content-Length for us, but Content-Type we set ourselves
var contentType:URLRequestHeader = new URLRequestHeader("Content-Type", "text/xml");

xml_request = new URLLoader();
xml_request.addEventListener( Event.COMPLETE, saveContentResult );
xml_request.addEventListener( IOErrorEvent.IO_ERROR, error );
xml_request.addEventListener( HTTPStatusEvent.HTTP_STATUS, httpResponse );

New toy

03 Aug

eeepad.pngI’ve been working with various devices and Flash the last half year and today I got myself a brand new toy, the ASUS Eee Pad Transformer. It’s the first Android tablet that has appealed to me in any way and the keyboard dock actually makes it usable as something more than just an entertainment-toy like the iPad is to me.

Don’t get me wrong though. Android is still miles behind Apple in terms of usability on their tablet OS, but HoneyComb 3.2 really isn’t bad at all and I needed a high resolution tablet (1280 by 752 pixels) for device testing. Getting my projects onto the device was absolutely straightforward except for one important thing - the device didn’t show up in Flash Builder initially.

Thanks to Mark Doherty and Twitter I got an answer in just minutes but it wasn’t exactly detailed: “you’ll need to add the oem code to a file called adb_usb.ini”. It took a few minutes to figure this out so I figured I’d post how to add any USB device to the Android SDK and Flash Builder 4.5 (an others) for future reference.

Open a Terminal window and at the prompt type this:
cd /Applications/android-sdk-mac_86

If your Android SDK is in a different location, just substitute the path above. Next, make sure you stop the ADB server by issuing the kill-command:
./adb kill-server

Next you’ll create the adb_usb.ini file. Open another Terminal window. By default, Terminal windows open at your home path and that’s just where we want to be. In this folder there should be a hidden folder called “.android”. You can’t see this using the OSX Finder, but if you type:
ls -la

you’ll see all the files in the directory. Enter the folder using the cd-command:
cd .android/

If you type “ls -la” again and no “adb_usb.ini” exists, type the following to create the file:
touch adb_usb.ini

The next step is adding support for the tablet/device vendor of your choice. You can edit this file using any good text editor or you can do it simply via the Terminal by typing:
echo “0x0b05” >> ~/.android/adb_usb.ini

That will append the hex value to the text file. In the line above, the characters “0b05” adds support for devices from ASUS. The full (but not complete) list of manufacturers can be found here: and using this you should be able to add support for any other USB-based device.

You finish off by restarting the ADB server:
./adb start-server

and then ask it to list devices connected:
./adb devices

On my machine this produced a list like the one below and made the ASUS Eee Pad Transformer device show up in Flash Builder as it should:
List of devices attached
370668942427457 device

I hope this is of use to others as well grin