Free Range Arduino


Looking to pair Arduino with mobile devices? Here are some notes from my Free Range Arduino presentation at FITC‘s Screens 2013.

Why?

Smartphones come bundled with powerful technology. Rather than buy and integrate sensors and communications, we can leverage the sensors already built into smartphones (Magnetometer, Accelerometer, Touchscreen, speakers, microphones etc.) and simultaneously augment our phones and the Arduino board. Bonus: we can use SMS and other amazing tech with our inexpensive buttons, switches and other triggers.

Bridging with a PC – many devices

Any phone browser that has websocket capabilities can be used to drive an Arduino. There are many ways this can be done but usually the structure involves an Arduino physically connected to a server and multiple web clients sending/ receiving data from that server. nodejs and noduino or node-arduino are great combos for this. Breakout.js is also very useful.

If you’re lucky, Breakoutjs requires very little to setup; it consists of a Java server that needs to be run and a firmata sketch that needs to be uploaded to the Arduino. The “getting started” example on the Breakoutjs site is helpful, but neglects to mention that you need to navigate to a test directory to try things out. For example, http://192.168.0.20:8887/examples/getting_started/blink_led.html

Mega ADK – Android devices

The Arduino Mega ADK lets us plug an Arduino board directly into an android device over an USB connection (e.g. type-a to the micro-b connector on many devices). Once connected, a custom application must be built to communicate between the android device and the Mega ADK. Probably, the easiest starting point for making an Android/ Arduino friendly application is the ADT (Android Developer Tools ide). However, documentation is generally poor and non-specific.

Bluetooth – Android devices

Using a Bluetooth Arduino module, like the Bluesmirf, you can connect directly to to your phone and communicate via an app. When used in conjunction with the powerful Amarino Toolkit you don’t really have to do much at all.

  • Install the Amarino apk on your Android device – available at the Amarino downloads page
  • Upload a sketch to your Arduino that responds to Serial data. Here’s my sketch.
  • Setup a bluesmirf and your Arduino board
  • Open Amarino and connect to your bluesmirf
  • Send messages to your board

Custom iOS cables – iOS Devices

Using the Redpark TTL Serial Cable, you can connect directly between a custom iOS application on your iOS device and your Arduino. Sadly, Apple requires special licensing for hardware enabled applications which will stop you from submitting your Arduino prototype to the App Store, but you can still upload directly to your device as long as you have the proper certification.

Paduino is a great pairing for this technique. The Paduino site offers downloads of an iOS app that can be built and deployed on your device and a sketch to deploy to your Arduino.

  • Connect the Redpark TTL Serial Cable to your Arduino board – you only need to connect the ground pins, Arduino rx to tx on the cable and Arduino tx to rx on the cable
  • Upload the Paduino friendly sketch to your board
  • Connect the Arduino to your iOS device
  • Open paduino

 

Custom FSK cable – whatever

This is my fav. technique. You use a TTRS audio connector (stereo and microphone audio) and the headphone jack on your device to send beeps back and forth between your Arduino and a custom application. This is the technique by which older modems operate. Frequency-shift keying involves modulating and demodulating (where we get the word ‘modem’ from) a signal so that it can be used to transmit data. An excellent introduction to FSK and Arduino.

Leave a comment

Gilded Crane

I’ve never been much of a fan of gold – I’ve always thought it lacks an aspect of the “understated” that I would associate with elegance. So, I’m entertained by my current obsession with the art of gilding – it has a delicacy that is incongruous with the gaudiness of gold accessories. If I’m honest, the Gilded Crane is something I merely wanted to see, but there is a lot that can be read into it.

In the Paper Dolls project I did with Breeyn McCarney, we explored the lack of value we attribute to materials like paper. Paper is something that is incredibly expensive to produce, at least when we use it as an infinite and disposable resource. The Gilded Crane could be considered another exploration of this. Origami adds value to paper through craft and artistry. Additionally, the illusion of value is added through gilding. To my knowledge, there is no way to effectively “harvest” or profit by the low financial value of gold leaf – in a sense, the gold itself has been disposed of since the act of gilding makes it impossible to reuse (without melting it off or burning the substrate).

Leave a comment

Slurpy Ford Wii Nunchuk Puppet

Use, spacebar, “c”, “s”, left, right, up and down arrows to control Slurpy:
Get Adobe Flash player

I’ve thought for a long time about how a Wii Nunchuk would be perfect for controlling a puppet. It has an accelerometer, a joystick and two buttons.

Accelerometers are sensors that measure proper acceleration – the orientation of an object relative to the Earth’s gravity. You can use an accelerometer to determine the direction that an object is facing. Probably the least expensive accelerometer is the Wii Nunchuk – off brand versions can be bought for $10 at big box stores. Additionally, they can be bought as chipsets that plug into arduinos – chips are usually start around $12 in physical stores and cheaper online, but you miss out on the benefits of the extra buttons/ joystick. Also, you can buy a Wii Nunchuk at a bigbox pharmacy at midnight on a whim.

Cut the end off the nunchuk and plug it into your arduino. Plug your arduino into a computer.
I’m using the wiichuck adapter from Todbot

It spits out serial data to whatever software you want to use. Sadly, you do need some scripting/ programming knowledge here. Fortunately, you can use all kinds of things, including node.

Here’s what the data looks like:
{“accx”:180, “accy”:125, “zbut”:0, “cbut”:0, “joyx”:122, “joyy”:130}

There was some interest in the assets and how they work. Here are the cutup pieces that I used:

Leave a comment

Etch-a-Sketch Turntables

Arduino Sketch

For an upcoming project with CTT, we decided to make a giant etch-a-sketch out of a quadcopter, a UV laser, a giant glow in the dark wall and two turntables. As part of a bonus project I made a real etch-a-sketch that is controlled by 2 turntables. The turntables replace the knobs by controlling two gearmotors that spin forward or reverse in very tiny increments. In addition, this approach allows for computer controlled illustrations and perhaps doing things like uploading an image and having it draw on screen – I’m almost done this. Automated Etch-A-Sketches have been done before, but I’m using my own approach.

This works by using Time Coded Vinyl. TCV is a vinyl record album that has a timecode pressed into it instead of a “traditional” audio track. The TCV is interpreted by a hardware controller and sent to a computer via USB connection.

The Traktor 2 Scratch Pro software interprets the position of the playhead using the data received from the hardware controller. There is a 1 second track that loops based on the record input for each of the two turntables and it’s the playhead position on this track that is used for the midi out. This is then sent from Traktor 2 to a virtual midi device (LoopBe1) which is software that’s designed to behave as though it were a piece of midi hardware. This is specified in Traktor 2 Scratch Pro under Preferences > Controller Manager.

NO YOU CHECK YOUR OUTPUT ROUTING, BITCH! btw, this is a s’up tag, so, you know, s’up?

I’m using Node.js to receive the data and send to the arduino. The Node.js application uses Justin Latimer’s node-midi to receive the midi in data and Voodoo Tiki God’s node-Serialport to send serial messages to the arduino.

The arduino sketch receives the messages via serial and uses a Pololu MC33926 to send messages to the two gearbox motors.

I’m not going to include my whole node.js application because I’m a bit crap at node and embarassed, but here’s the whole server.js sketch. It should be all you need after you install the dependencies mentioned above:

(function() {

var midi;
midi = require(“midi”);
var SerialPort = require(“serialport”).SerialPort
var serialPort = new SerialPort(“COM13″, {
baudrate: 115200
});
serialPort.on(“open”, function () {
console.log(‘open’);
serialPort.on(‘data’, function(data) {
console.log(‘data received: ‘ + data);
});
});
var port = 0;
var input = new midi.input();

console.log(‘port count: ‘+input.getPortCount());
console.log(‘port name: ‘+input.getPortName(port));
var last_position = {a:0, b:0}
var seek_position = 1;
var max_speed = 0.1;
var max_range = 20;
var moving = {x:false, y:false}
input.on(‘message’, function(deltaTime, message) {

//console.log(message);
if (message[0] == 190){
//deck a
seek_position = message[2]/127*100;
diff = (seek_position – last_position.a);
last_position.a = seek_position;

if (Math.abs(diff) > 90){
return;
}else{
if (diff < 0){
//console.log("A right:" + diff);
moveDrone("right", (Math.min(Math.abs(diff)/max_range)*max_speed, max_speed));
}else if (diff >0){
//console.log(“A left:” + diff);
moveDrone(“left”, (Math.min(Math.abs(diff)/max_range)*max_speed, max_speed));
}else{
//should never happen
//console.log(“stop”);
moveDrone(“stop”, 0);
}
}

}else if(message[0] == 191){
//deck b
seek_position = message[2]/127*100;
diff = (seek_position – last_position.b);
last_position.b = seek_position;
if (Math.abs(diff) > 90){
return;
}else{
if (diff < 0){
//console.log("B up:" + diff);
moveDrone("back", (Math.min(Math.abs(diff)/max_range)*max_speed, max_speed));
}else if (diff >0){
//console.log(“B down:” + diff);
moveDrone(“front”, (Math.min(Math.abs(diff)/max_range)*max_speed, max_speed));
}else{
//should never happen
moveDrone(“stop”, 0);
}
}
}
});
function moveDrone($dir, $speed){
switch ($dir){
case “front”:
serialPort.write(“u\n”);
break;
case “back”:
serialPort.write(“d\n”);
break;
case “left”:
serialPort.write(“l\n”);
break;
case “right”:
serialPort.write(“r\n”);
break;
}
return;
}

input.openPort(port);
}).call(this);

The motors either advance or reverse in 10ms increments, hammering the motor shield with constant, tiny instructions. Because of the short increments, it appears to be continuous and fairly responsive to the record movements.

Leave a comment

Dragon Pumpkin Spring

For my recent talk at FITC’s Spotlight: Hardware, I decided to revisit my Halloween project the Dragon Pumpkin. Pumpkins are hard to find this time of year so I improvised with a watermelon. Everytime you say the words “trick or treat” a fireball is shot out of it’s mouth. How to make a dragon pumpkin.

Dragon Pumpkin Spring from Christopher Lewis on Vimeo.

The Microsoft Kinect has a lot of powerful motion technology, but it also has an under appreciated microphone array which is great at localising audio, reducing background noise and text recognition.

Leave a comment

Mouse Hacks

On June 8, 2013, I gave a presentation at FITC’s Spotlight: Hardware. It was a great event that covered many topics related to hardware and physical computing. As silly as it is, I presented what I think is one of the best ways to get into making physical interactive installations is by doing “mouse hack”.

A mouse is the quickest and easiest way to include digital interaction in real objects with the added bonus that mice are fairly inexpensive and people often have a few kicking around. The goal is to add a couple of wires that will be another way to perform a click. Because a mouse click is an “OS” level interaction, no or few programming skills required. Also, using a wireless mouse means you can create a wireless digitally enabled interactive object. If you do need to buy a mouse, $5.99 is the most inexpensive price I could find in the real world – I’m sure you can find cheaper online. The important thing to remember is that mice are inexpensive, so you shouldn’t be afraid of opening them and maybe screwing up.

Tools:
Mouse
Wire – anything will do, but hookup wire is the best
Wire Strippers – an exacto works – “automatic” wire strippers are the best
Screw Driver
Pliers (optional)
Solder (optional)
Solder Gun (optional, but highliy recommended
Electrical tape – so helpful

Soldering scares a lot of people, but it’s a great technique and will make the whole thing easier. I think this is the best video I’ve seen about how to solder:

Insert the battery into the mouse to make sure it works. If the mouse has one of those annoying on/off switches, turn the mouse on and then remove battery. These switches pop out and get lost, so you want to make sure that the mouse is on in case you can’t get the switch back in position.

Often the screws are hidden under LRF. (little rubber feet) Pull off the LRFs to reveal the screws, and set them aside. Unscrew the case and open up the mouse.

Take a photo to remember where things go. Sometimes it’s good to tape parts that look loose – the battery housing and mouse wheel, in my case. Look for the thing that might be a button – it’s marked SW1 on this particular mouse – presumably for “Switch 1″.

Put your hand over the mouse to make sure it’s the correct button – nothing bad will happen if you press the button.

Pull the circuit out. Things might pop out. Oh well.

There are two little nubs directly under the button. Touching these nubs together is the same as clicking the mouse button – nice!

Strip the wires. I like to tie a knot in them so they stay close together and are easy to work with.

Put the wire through the stripper and align it to the correct guage. If you don’t know, then eyeball it.

Use some pliers to wrap the stripped wire around the nub. Solder it into position. If you’re afraid of soldering, you can use electrical tape, but it won’t be as reliable.

By this point the on/off switch has probably fallen out. Worry about it later or throw it away. Good thing you made sure the mouse was turned on earlier.

Try your best to put some tape between the two wires – if they touch by themselves it will count as a click, so you want to avoid that. You can use hot glue if you have trouble – it’s not the best approach, but it’s the easiest.

Put your finger over the mouse to make sure you got the correct button – I’ve screwed this up a few times.

Shove everything back together

Cut a notch in the front so the wires have a place to come out of the housing.

Close the mouse, turn it on, plug it in and touch the wires together – that’s it.

You could embed these mice in:
Footplates, switches, fridges, cookie jars, medicine cabinets, pill bottles, exercise equipment, etc.

Counters

You can now use the mouse to count things. This can be done easily by creating a simple html page with a button. Positioning the mouse over the button and touching the two wires together counts as a click. This requires very little HTML:

<html>
<head>
<script type=”text/javascript”>
var countTotal = 0;
function countClick()
{
countTotal ++;
document.getElementById(“countOutput”).innerHTML = “<h2>Count Output: “+countTotal+”</h2>”;
}
</script>
</head>
<body>
<div id=”countOutput”><h2>Count Output</h2></div>
<button type=”button” onClick=”countClick()”>COUNT</button>
</body>
</html>

Click Count Demo

Tying the button click to something like a google analytics event would hypothetically allow you to permanently store your results online.

Why is this approach better than a physical count clicker? Storing data digitally, not requiring mechanical activation and being able to add this to almost any object are definite benefits.

Trigger

Audio or video can be easily triggered by a mouse click if the media player is in full screen mode. Quicktime, Youtube, Flash and VLC can all be setup to do this.

Still images can be triggered using Keynote/ Powerpoint or a picture viewing app. like irFanView

You can even make an html based presentation by using Javascript to hide the mouse and advancing a background image. In The Evolution of Type Demo with graphic by Mikaela Couch, the background advances with each mouse click. If the mouse wires were embedded in a physical object, such as a printing press, you could make pulling a lever the trigger action to advance the timeline display.

1 Comment

Get to know me on FITC.ca

Here’s an interview I just did with Caroline at FITC. In it, I discuss some of the work I’ve been doing with the group Creative Technologists of Toronto, some of my reasoning for being a maker and what I’m going to be discussing at the upcoming Spotlight: Hardware event: Get to know Christopher Lewis

Come meet me and members of Creative Technologists of Toronto when I present at Spotlight: Hardware on June 8. Use the discount code ‘cttoronto’ for 10% off.

Leave a comment

Dragon Pumpkin

Dragon Pumpkin – Halloween 2012 from Christopher Lewis on Vimeo.

I decided to add a bit of “Trick” back into Halloween. The Dragon Pumpkin is a voice activated fire breathing pumpkin; saying the words “Trick or Treat” triggers a fireball. What’s more awesome than fireballs?

DSC_3961

The Windows Kinect has a 4 microphone array and amazing speech recognition capabilities. Using the Speech Basics example that is packaged with the Kinect SDK, a C++ application recognizes the phrase “Trick or Treat” and sends a serial message to the Arduino. A simple sketch on the Arduino receives the serial message and turns on pin 13 – fairly standard – which fires a solenoid circuit triggering the fireball.

DSC_3951

DSC_3949

This whole project is extremely dangerous, so I officially discourage anyone from attempting to make a fireball. I’m skipping that step of my build intentionally. However, I would recommend getting in touch with your nearest Hacker Space if you’re interested in learning how to make a “poofer”. I wouldn’t advocate anyone else playing with fire, but what I learned about controlling an arduino via Kinect voice commands is quite useful.

DSC_3944

DSC_3935

The most difficult part of the whole project was getting Visual Studio installed and running.

DSC_3933

For those interested in getting a Kinect for Windows talking to arduino, here’s a light overview of what I did:

Kinect Voice Recognition

Kinect for Windows

I’m not sure if I’m allowed to redistribute the Microsoft Kinect examples, so instead of supplying a file, here are the steps I took:

  1. Download and install Visual Studio 2012
  2. Download and install Microsoft Kinect SDK, Toolkit and Microsoft Speech Platform
  3. Open the Microsoft Kinect Toolkit Browser
  4. Go to the Samples: C++ tab
  5. Scroll down to the Speech Basics D2D and Install
  6. Open the Speech Basics D2D in Microsoft Visual Studio 2012
  7. Edit the SpeechBasics-D2D.grxml file. This is where you add the words. My file looks like this:
    <grammar version="1.0" xml:lang="en-US" root="rootRule" tag-format="semantics/1.0-literals" xmlns="http://www.w3.org/2001/06/grammar">
      <rule id="rootRule">
        <one-of>
          <item>
            <tag>TRICK OR TREAT</tag>
            <one-of>
              <item> trick or treat </item>
            </one-of>
          </item>
        </one-of>
      </rule>
    </grammar>
  8. In SpeechBasics.cpp add your Trick or Treat action. For example:
    const SpeechTagToAction Map[] =
        {
            {L"TRICK OR TREAT", TurtleActionTrickOrTreat}
        };
  9. In TurtleController.cpp I added the following at the top of the file:
    #include<stdio.h>
    #include<stdlib.h>
  10. Here’s where the Kinect messages the arduino via serial. In TurtleController.cpp add a case for your Trick or Treat action to the switch statement in the “void TurtleController::DoAction(TurtleAction action)” code block. I got rid of the cases for all the other directions:
    case TurtleActionTrickOrTreat:
            m_CurrentDirection = NextDirection(m_CurrentDirection, false);

            // We take a left turn to mean a counter-clockwise right angle rotation for the displayed turtle.
            m_CurrentRotationAngle -= 47;

                    FILE* port;
                    system( "MODE COM4: BAUD=9600 PARITY=n DATA=8 STOP=1" ) ;
                    port = fopen( "COM4:", "wb" ) ;
                    printf("1");
                    fprintf( port, "1" ) ;
                    fclose( port ) ;
            break;
        }

  11. Edit SpeechBasics.cpp and replace the SpeechTagToAction method with the following
    const SpeechTagToAction Map[] =
        {
            {L"TRICK OR TREAT", TurtleActionTrickOrTreat}
        }
  12. In TurtleController.h replace the “enum TurtleAction” block with the following:
    enum TurtleAction
    {
        TurtleActionTrickOrTreat,
        TurtleActionNone
    };
  13. That should be it – I think… Compile and you should have something that recognizes your Kinect and sends a serial message to your arduino. If the modifications work, the Turtle should turn 45 degrees everytime you say “Trick or Treat”.
    Kinect Application

The Arduino Sketch

  1. I’m using a pretty simple sketch, modified from the blink sketch and Arduino Serial Communication:
    int firePin = 13;
    int state=0;
    void setup() {
        pinMode(firePin, OUTPUT); // pin will be used to for output
        Serial.begin(9600); // same as in your c++ script
    }

    void loop() {
      if (Serial.available() > 0)
      {
        state = Serial.read(); // used to read incoming data

        switch(state)// see what was sent to the board
        {
          case ’1′: // if the the one was sent
            flameOn();
            delay(750);
            flameOff();
          break;
          case ’0′: // if 0 was sent
            flameOff();
          break;
          default:
          break;
        }
      }
    }
    void flameOn(){
      digitalWrite(firePin,HIGH);
    }
    void flameOff(){
      digitalWrite(firePin,LOW);
    }

  2. Run the sketch. When the Serial message “1″ is sent to the arduino, the on-board led or whatever is on Pin 13 will light up.

serialFlameControl.ino

The solenoid circuit is attached the Pin 13 on the arduino. It allows for a Transistor to activate a 12v solenoid without frying the arduino board. The circuit was taken from Controlling Solenoids with Arduino.

Arduino and custom Solenoid Circuit

DSC_3913

More photos

Special Thanks to Demi at SplitElement Inc. for the use of the Kinect for Windows and to LB for the voice talent.

4 Comments

Digital Opera Backdrops – Cavalleria Rusticana and Pagliacci

In October 2011, I was Art Director for performances of Cavalleria Rusticana and Pagliacci, directed by Jessie Fraser and performed by Opera Belcanto. The two operas are often performed together as a double bill since they’re both fairly short and are thematic and stylistically similar.

I created a digital backdrop in the form of a fullscreen Flash application that could be controlled by the theatre staff. Hitting different shortcut keys would initiate different sequences of the backdrop which were timed to match the performance.

Cavalleria Rusticana - Day 2

Both operas featured a timelapse video of the sky, captured from my balconey, to evoke the passage of time.

Cavalleria Rusticana - Day 2

During the introduction of Cavalleria Rusticana, elements of the small Sicilian town, Vizzini, fade in to establish the location. The town was created by Photoshopping elements from a variety of sources. Some of the elements were taken from rights-cleared photos of the real town Vizzini. Additional details were taken from my own photography, such as a stone fence photographed at Riverdale Farm; it’s a Toronto/ Vizzini mashup.

Cavalleria Rusticana - Day 2

At one point during the Cavalleria Rusticana, there is an Easter procession. To fill out the number of performers, I created a sequence featuring silhouettes of procession participants, triggered by shortcut key.

Cavalleria Rusticana - Day 2

To match the content of the opera, a wine shop and church were included as prominent elements in the backdrop. Additionally, a British style vardo (gypsy wagon) is parked behind the wine shop; I added the vardo to connect the two operas. It’s implied that the performers were performing in Vizzini before appearing in Pagliacci. At the risk of spoilers, both operas feature murder following affairs; I was amused with the idea that murderous rage was like a disease that the Pagliacci characters brought with them from Vizzini. I included the original poster for Pagliacci on the wine shop wall in my depiction of Vizzini and again in Pagliacci.

Cavalleria Rusticana - Day 1

To transition between the two operas, I gradually faded out elements of Vizzini and played the sky timelapse quickly in reverse to return to day.

Pagliacci - Day 2

Pagliacci was set in the small town of Taormina where travelling performers arrive to entertain the town. I decided that the performers would set camp and perform in a secluded or less travelled area on the outskirts of town, similar to the locations that circuses always seem to be located. The covered area on the left and brick wall are both from the pig pen at Riverdale Farm.

Pagliacci - Day 2

A shortcut key was added to darken the backdrop to create a more intimate scene.

http://www.flickr.com/photos/blacksanta_69/6270895286/in/set-72157627830034153/

Pagliacci - Day 2

During the curtain call, the backdrop fades out to bring the audience back to reality. I’m proudly receiving my adulation on the very far left.

Leave a comment

A Twitter Follow Button for AS3 Flash

Follow and Mini-profile

Earlier this year, Twitter introduced Web Intents as an easy way to Tweet, Reply, Retweet, Favorite, and Follow. Web Intents are meant to be used with popups, which means I can easily adapt from my previous Tweet Button for Flash technique: add a javascript popup to the page, set some variables and call the popup from Flash.

Twitter introduced a Follow Button that behaves similarly to the Tweet Button, but their claims that it, “uses the same implementation model”, is the tiniest bit bullshit. The Follow Button relies on Javascript in ways that we can’t easily use with Flash.

Our Web Intent Follow Button opens a popup window with a Mini-profile page, as pictured above. The Web Intent Follow Button uses either one of the following two values:

  • screen_name is the name of the twitter user you’d like to follow. e.g. @blacksanta_69
  • user_id is the id of the twitter user you’d like to follow. I had a hard time finding my twitter id so I’m using screen_name instead.

Like before, you drop the ‘www’ when using Web Intents.

1. The Popup Javascript function needs to be added to your html page in the <head> part of the page. The width and height are hardcoded in the javascript to reflect the Twitter recommended dimensions of a Tweet window. However, this can easily be passed as a parameter from Flash if you want.

function openTweetWin (url) {
window.open(url, "tweetThis", "width=550,height=450,toolbar=no,scrollbars=no");
}

2. Create a button in flash with the instance name btn_follow and add the following code. It’s worth noting that this works everywhere except within the Flash IDE, so test it on the html page

//Add an Event Listener for the button
btn_follow.addEventListener(MouseEvent.CLICK, clickFollow);
btn_follow.buttonMode = true;

function clickFollow(e:Event):void{

        //The path to the follow "intent" page
        var path:URLRequest = new URLRequest("https://twitter.com/intent/user");
       
        //using the GET method means you will use a QueryString to send the variables
        //twitter likes this. This is used as an alternate method if we don’t use
        //a javascript popup
        path.method = URLRequestMethod.GET;
       
        //The URLVariables class is a nice way to keep everything organised. There is the added bonus
        //that we can use these values if we GET instead of using the Javascript popup.
        var tweetVars = new URLVariables();
        tweetVars.screen_name = "blacksanta_69";
        //tweetVars.user_id = "";
       
        //Set the URLRequest to include the URLVariables
        path.data = tweetVars;
       
        //If Flash is okay with us using ExternalInterface
        if (ExternalInterface.available){
                try{
                        //We’re going to pass this as a string to javascript, so we have to
                        //"stringify" it instead of using the URLVariable + URLRequest approach
                        //I’m putting a dummy placeholder in the first position of the
                        //QueryString so that I can shuffle my variables around without
                        //worrying about who gets a ‘?’ instead of a ‘&’. It’s faster than
                        //writing a quick if statement, but commenting about it takes far more time ; )
                        path.url +="?d=0";
                        for (var each in tweetVars){
                                path.url += "&"+each+"="+tweetVars[each];
                        }
                       
                        //Make a call to the openTweetWin Javascript function
                        //and pass it the ‘stringified’ version of the QueryString
                        ExternalInterface.call("openTweetWin", path.url);
                } catch (error:SecurityError){
                        //If it doesn’t work just open a damn window.
                        navigateToURL(path, "_blank");
                } catch (error:Error){
                        //If it doesn’t work just open a damn window.
                        navigateToURL(path, "_blank");
                }
        } else {
                //If it doesn’t work just open a damn window.
                navigateToURL(path, "_blank");
        }
}

Gives you:
Get Adobe Flash player
Source FLA Here

In HTML

<!– Simply take the link to twitter and add a querystring (denoted by the ‘?’) at the end with your text Use the ‘+’ symbol instead of spaces so browsers can understand (this is called escaping and can be done with javascript) –>
<a href="https://twitter.com/intent/user?d=0&screen_name=blacksanta_69" target="_blank">Follow</a>

Gives you:
Follow

Because there are so many easy to use features with Web Intents, the logical next step would be to build AS3 classes.

Leave a comment