Friday 2008/04/25
4:05 PM

Categories: Flash/Actionscript, Technology's Betrayal, Web Dev, Work

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:

Actionscript:
  1. var tmessage:String = "%26%23174%3B";
  2. var req:URLRequest = new URLRequest("mailto:?subject=hello&body=" + tmessage);
  3. navigateToURL(req);

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:

Actionscript:
  1. package
  2. {
  3.     import flash.net.URLRequest;
  4.     import flash.net.*;
  5.     import flash.display.Sprite;   
  6.    
  7.     public class SendToFriend extends Sprite
  8.     {
  9.        
  10.         private const MESSAGE:String = "This message is from dirtystylus®";
  11.        
  12.         public function SendToFriend(): void
  13.         {
  14.             send();
  15.         }
  16.    
  17.         private function send():void
  18.         {
  19.             var _req:URLRequest = new URLRequest("mailto:");
  20.             var variables:URLVariables = new URLVariables();
  21.             variables.subject = "hello";
  22.             variables.body = MESSAGE;
  23.             _req.data = variables;
  24.             _req.method = URLRequestMethod.GET;
  25.             navigateToURL(_req);
  26.         }
  27.     }
  28. }

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.


Responses


Nick

Thursday 2010/04/15 9:09 PM

Thanks you saved me!


Nick

Monday 2010/04/19 5:39 PM

Did you have any problems with this displaying in Outlook on the PC?

For some reason its adding the  character before the registered symbol for us, but not on the mac.

My output looks like this in the email body:

MasterCard®!

Thanks.


ds

Tuesday 2010/04/20 12:31 AM

Nick, I can’t remember how it rendered on Outlook. Does it render that way in web clients like Gmail?


Leave a Response