Generating a Code Signing Request using OpenSSL for Windows

If you’re developing apps for iOS (iPhone, iPod touch or iPad) you’ll need to generate a 2048-bit Code Signing Request (CSR) before you can create a Development Certificate and start testing your apps.

On OS X, you can use Keychain Access, but on non-server editions of Windows it’s a little less straight forward. Here’s how:

  1. Download and install the latest version of OpenSSL
  2. Once installed, you will need to add the OpenSSL bin folder to your PATH environment variable, e.g. c:\openssl\bin; if you’re not sure how, Google has the answer
  3. Open a command line window by selecting Start > Run… and entering “cmd”, then pressing OK
  4. To make sure you can find your CSR once it’s been created, type the following and press return:
    cd desktop
  5. To create your CSR, type the following an press return:
    openssl req -nodes -newkey rsa:2048 -keyout request.key -out request.csr
  6. Answer each of the questions
  7. That’s it: your CSR should be waiting for you on your Desktop, ready for upload to the iOS Provisioning Portal

Once your CSR has been approved and you have your Developer Certificate, you’ll need to convert it to a P12 file: instructions are here

Static initializers in AS3

Recently, several people have asked whether it’s possible to create some kind of constructor for static classes in ActionScript 3, and the answer is: yes!

The solution is  a static initializer. This is a block of code, surrounded by curly brackets but no function or var declaration, that runs the first time a property or method of a static class is called. Static initializers are called before any property value is returned or function executed, in the same way a constructor always runs before you can access the properties or methods or a regular class.

package
{
    public class MyStaticClass
    {
        // This is the static initializer
        {
            trace("Running static initilizer!");
            staticInitializer();
        }
        
        // We're calling a secondary method so we can use local variables
        static private function staticInitializer():void
        {
            var now:Date = new Date;
            baseColor = now.hours > 16 ? 0x000066 : 0x0000FF;
        }

        static public var baseColor:uint;
    }
}

Although it’s not strictly necessary to call a secondary method, Flash Player will throw an error if you declare local variables within the static initializer itself.

To prove that the static initializer is running first, simple trace out the baseColor property:

trace(MyStaticClass.baseColor);

If it’s after 4pm, this will result in the following output in the console window:

Running the static initializer!
102

Essential Eclipse plug-ins for Flash Builder 4 and Burrito

With the recent relase of Adobe Flash Builder 4, we thought we’d flag up the update URLs for a few of our favourite Eclipse plug-ins to save you having to hunt around for them.

To install plug-ins:

  1. Copy the appropriate URL to your clipboard
  2. In Flash Builder, select Install New Software… from the Help menu
  3. Click Add, paste URL in the Location field and click OK
  4. Select the plug-ins to install and click Finish

If you’ve spotted anything we’ve missed, add a comment or  tweet it to @mesmotronic.

Eclipse.org

This URL contains links to most of the plug-ins hosted on Eclipse.org, allowing you to add functionality like ANT, JDT (Java Development Tools) and PDT (PHP Development Tools). You’ll also need to add this URL to Flash Builder to enable you to install other plug-ins, like soapUI:

http://download.eclipse.org/releases/galileo/

Subclipse (SVN)

If you’re a regular user of version control, and you should be, the subclipse plug-in is essential:

http://subclipse.tigris.org/update_1.6.x

soapUI

For anyone who uses Web Services, soapUI offers a great way to view and test your services:

http://www.soapui.org/eclipse/update/site.xml

Android SDK

Now that you can develop application using AIR for Android, it could be argued that ADT (Android Developer Tools) isn’t necessarily essential, but if you’re looking to develop mobile apps for anything other than the latest handsets it’s definitely worth a look:

https://dl-ssl.google.com/android/eclipse/

TODO/FIXME

For anyone who makes regular use of the Tasks panel in FlashDevelop or Eclipse’s Java profile, this is a must.

You can download the plug-in here (requires manual installation).


					

Creating a simple HTTP proxy using PHP

Cross domain policy files, or rather a lack of them, are the bane of Flash and Flex developers’ lives. Whether it’s the Twitter API, data from Yahoo! Finance or one of any number of other data sources, the moment your SWF makes it to the web you’re faced with the same problem: Security Error!

The solution is to create a simple proxy on your server that can load the data for you and pass it to your application. If you’re using PHP, then this is about as simple as it gets:

// Too simple! (see comment below)
<?=file_get_contents($_REQUEST['url'])?>
<?php
$url = $_REQUEST['url'];
if (preg_match('/\b(https?|ftp):\/\/*/', $url) !== 1) die;
echo (file_get_contents($url));
?>

The preg_match ensures that the requested URL is valid and offers basic protection against anyone trying to maliciously access files on your server.

That’s it. Just paste that into a text file, save it as proxy.php and upload it to your server. You can then access any data you like simply by passing it a URL. Best of all, it works with both GET and POST, for example:

http://www.mydomain.com/proxy.php?url=http://blog.mesmotronic.com/index.php/feed

Happy proxy-ing!