So Flash, the Registered TM Symbol, and a URLRequest walk into a bar…

At work we ran into a little issue on how to pass the registered trademark symbol ® from flash to the user’s mail client via a mailto: call. We originally tried jamming it into the string like so:

[code]
var tmessage:String = "%26%23174%3B";
var _req:URLRequest = new URLRequest("mailto:?subject=hello&body=" + tmessage);
navigateToURL(_req);
[/code]

We had hoped that the email client would receive the string and decode it properly, but instead it simply rendered it as ®. Searching the web for help was complicated because “register” and “registration” appear so often in forms and unrelated content.

In the end, some experimentation and reading of the documentation for the URLRequest class led us to this solution:

[code]
package
{
import flash.net.URLRequest;
import flash.net.*;
import flash.display.Sprite;

public class SendToFriend extends Sprite
{

private const MESSAGE:String = "This message is from dirtystylus®";

public function SendToFriend(): void
{
send();
}

private function send():void
{
var _req:URLRequest = new URLRequest("mailto:");
var variables:URLVariables = new URLVariables();
variables.subject = "hello";
variables.body = MESSAGE;
_req.data = variables;
_req.method = URLRequestMethod.GET;
navigateToURL(_req);
}
}
}
[/code]

The URLRequest class has a data property, to which one can assign a URLVariables object containing stuff that we were trying to jam into the string as name/value url-encoded values. Assigning the variables to the data property also automatically urlencodes them before the URLRequest is sent, so in the final solution we just plugged the “®” symbol directly into the string, and it was urlencoded properly and emerged in the email body intact.