Friday, January 7, 2011

Sending an email from your Flex app just got easier (short post)

I want to send an email from my Flex app.  Well, if I don't have a backend mailserver setup, and I want my user to send me a message about, say, the app's service crashing, the easiest way to do this is through URLRequest!

Quick demonstration - 

1) Create the url request: 

var u:URLRequest = new URLRequest("mailto:"+EMAIL_ADDRESS);

2) Create a variable for the subject and body:

var v:URLVariables = new URLVariables(); //interestingly, you can put all the variables into a string and pass that in, but here we're just going to append them as properties to the object

3) Assign those properties:

v.subject = "Application crashed";
v.body = TEXT_OF_CRASH_MESSAGE;

4) Pass those variable properties into the URLRequest:

u.data = v;

5) Navigate to the URL:

navigateToURL(u, "_self"); //the _self is .js and not required

This is an easy way to pass any valuable info from your flex app into your user's default email program (Entourage/Outlook, Thunderbird, Mail, etc.)

Thursday, January 6, 2011

Error #2173: Unable to read object in stream


I've been working on building up async tests (which I should have a different post for shortly), and came across this annoying error:

ArgumentError: Error #2173: Unable to read object in stream.  The class com.lordB8r.model.Control does not implement flash.utils.IExternalizable but is aliased to an externalizable class.
at ObjectInput/readObject()
at mx.collections::ArrayList/readExternal()
at mx.collections::ArrayCollection/readExternal()


Finding FlashSecret's comment helped, but didn't get me all the way there.  While I could put the path inside an array, I wasn't assigning the return value to an array, or Control.  Instead, I needed to import a/the class(es) needed by IExternalizable in my test.  So, simply putting this in my test class made it work:

import com.lordB8r.model.Control;


Is this correct for testing?  I'm not sure, but it helped me get my async test to retrieve data from a Spring RESTful service.  Test passed because I got data, but only once I told my test what data type it should be expecting.

I've dealt with this when bootstrapping an application, also when requesting data back from the server.  Often times, my service class (or service recipient) doesn't know the type I just asked for, so I need to import it into that class.