NAME A Sample Subscription Form Using Flash

Mojo Mail now has hooks for Flash that will return an SWF-friendly, XML document to allow you to create a subscription form in the animation itself, instead of having to use HTML form widgets. All the SWF animation has to do is load mojo.cgi with the correct query string, which looks like this:

        http://yoursite.com/cgi-bin/mojo/mojo.cgi?f=subscribe_flash_xml&;l=listshortname&e=someone@address.com

Breaking that down,

http://yoursite.com/cgi-bin/mojo/mojo.cgi
The full URI to where Mojo Mail has been correctly installed. Before I get any further, please install Mojo Mail and have it working before trying to make it work in Flash, you'll save yourself so much time. I've found, especially when developing Flash animations on a Mac, that weird and wonderful things happen in animations once the word 'XML' enters the picture.

f=subscribe_flash_xml
'f' is short for 'flavor', the hip way to tell Mojo Mail what you want it to do, it dates back to when Mojo was a part of my coffee speak (e.g. Mo' Joe) If you want to geek it, think of 'f' as in function. The flava we want to use is called 'subscribe_flash_xml' This will return a SWF-friendly XML document back to your animation

What do I mean by SWF-friendly? It means the XML doc that gets past back should work for all versions of the Flash 5 player and above, it does not have any newlines in it, or whitespace between tags, so you don't need any groovy undocumented Flash 5 XML method calls or #included code. All the tags are lowercase as well. I know, I've been there. I'm on your side, believe me. Oh, and the XML is given to Flash with a content type of 'application/x-www-form-urlencoded'.

l=listshortname
replace 'listshortname' with the list's shortname you want to make the subscription form for. The list's shortname is NOT the list name... shortened. If you created your list using version 2.6 and above, you were ask to make a shortname, for things like this. If you created your list with a version below 2.6 than you list's shortname is your list name.

e=someone@address.com
'e' is short for email, change it to the email you want to subscribe to.

Once you sort all that out, it's just a simple call in Actionscript:

        var Mojo = new XML(); 
            Mojo.load('http://yoursite.com/cgi-bin/mojo/mojo.cgi?f=subscribe_flash_xml&;l=listshortname&e=someone@address.com');

to load up the XML. Well, what does the XML look like?

The Returned XML

The XML document for this query:

        http://yoursite.com/cgi-bin/mojo/mojo.cgi?f=subscribe_flash_xml&;l=listshortname&e=someone@address.com

will look like this: (newlines added for clarity)

        <subscription>
         <email>someone@address.com</email>
         <status>1</status>
         <errors></errors>
        </subscription>

Pretty self-explanitory, (ah, the wonders of meta data) The only elusive thing is the status. A status of 1 means everything checked out. The listshortname flava checks to see if - the list exists, the email is valid, the email is already subscribed, if the list is closed and if the email is blacklisted. Possibly better than the self-rolled version you may have been using.


A query like this:
        http://yoursite.com/cgi-bin/mojo/mojo.cgi?f=subscribe_flash_xml&;l=listshortname&e=bad

Will return something like this:


        <subscription>
         <email>bad</email>
         <status>0</status>
          <errors>
           <error>invalid_email</error>
          </errors>
         </subscription>

Pretty slick, eh?

The error values are as follows:


again, self explainitory.


Working Example

There's an .fla file called email_subscription_form.fla In the first frame of Scene 1, there are two variables you need to change... have at it.

The above instructions are meant to be digested by someone who knows what they're doin' in Flash Actionscript. Tutorials by me for Flash are up in coming.

DEBUGGING

Sometimes using XML from an outside source within Flash can be difficult to debug, so I made it easy for you to just check out the XML doc in your browser add &test=1 to the end of the already-too-large-to-type-yet-again query string and paste that into a web browser.

FAQS


AUTHOR

Justin Simoni

http://justinsimoni.com


CONTACT

For support for this script, it's best to either post on the Mojo Mail message boards:

http://mojo.skazat.com/support/boards

or, subscribe to the Mojo Mailers discussion list:

http://mojo.skazat.com/cgi-bin/mojo/mojo.cgi?f=s&l=mojo_mailers