| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

TutorialFlashSetup2009

Page history last edited by Bjoern Hartmann 15 years ago

 

Overview

In our tutorial, we will control sensors and actuators from Flash through the Arduino physical computing platform. Flash cannot talk directly to the Arduino hardware, so you'll have to install some extra pieces of software: an Actionscript library for Flash that sends/receives Arduino commands over a network socket; a proxy server that translates network packets into serial bytes; and a hardware driver to connect to the serial port on the Arduino board.

 

Before the Tutorial

Complete these steps BEFORE comming to the tutorial - we have a packed schedule and not enough time to walk everyone through the software setup.

 

  1. You need a working version of Adobe Flash CS3 Professional on your computer. Non-professional CS3 may work, but has not been tested. Flash CS4 Professional may work, but has not been tested. Earlier versions of Flash that lack Actionscript 3.0 will definitely not work. We've experienced some trouble with installing Flash CS3 Pro Trial on 32bit Vista. Here are instructions for correcting Internal Error 2739 during installation.
  2. Download all necessary files:
    1. Arduino IDE: This is the programming environment to write and upload programs onto your Arduino board. It includes a "serial proxy" function that marshals messages between Flash's TCP socket and the virtual serial port. It also comes with a driver for the USB chip on the Arduino board. The driver creates a virtual serial port that can be used to exchange messages with the Arduino board.We are using a pre-release version that's not yet widely available.

       

    2. Mac Windows
      Download arduino-0013-mac-serproxy-dist20090101.zip Download arduino-0013-win-serproxy-dist20090102.zip
       
    3. as3glue library: A library for Flash to send/receive Arduino commands over a TCP socket. Download the latest as3glue_v2 zip file from the as3glue Google Code project. Inside you will find a folder called "Glue". Extract it into your workspace (e.g., c:/code/ on a PC or /Users/yourusername/Documents on OS X) - remember where this directory is for the following steps.
    4. CS247 Examples: A number of examples we will use in the tutorial. Download from bitbucket.org/bjoern/as3glue-examples-cs247 (choose download->zip from the menu bar). Also extract into your workspace and remember the path.

  3. Install Arduino IDE & FTDI Serial driver. Unzip the Arduino IDE into your Applications folder. Then look for the FTDI driver in subdirectory Arduino/drivers. Run the installer for your platform. If you have trouble finding this file, you can also get the latest "VCP driver" from FTDIchip.com.

    Note: If you already had an older version of the Arduino IDE installed on your computer, you may need to delete your existing Arduino preferences.txt file.

    • The location of your preferences file is shown under Arduino->Preferences (mac) or File->Preferences in the Arduino IDE. Write down this path.

    • Close Arduino IDE. Find the preferences.txt file  on your drive and delete it manually (while Arduino is NOT running) - Arduino will re-create it on the next startup.

  4. [ Optional: Upload Firmata Firmware to your Arduino board] Your board should have come pre-configured with the right Firmata firmware to talk to as3glue. If not, use the Firmware provided in the as3glue package: Open Glue/arduino/Firmata2/StandardPlusServoFirmata2/StanfardPlusServoFirmata2.pde in Arduino and upload it to your attached Arduino board.
  5. Configure Flash to include as3glue library: You'll have to add the as3glue library to the classpath so Flash can find the files when it compiles your projects.
    • What to do: Start Flash. Create a new File (there's a bug in Flash CS3 where preference changes are not taken over if you don't have a file open when setting preferences).
    • On a PC: Go to Edit Menu->Preferences; on OSX, the Preferences dialog can be found under the "Flash" Menu.
    • Within the Preferences dialog, click ActionScript->ActionScript 3.0 Settings...->"+" to add new directory to classpath.
    • Click the crosshairs to find the as3glue/as3 folder. In Flash CS4, there are three kinds of paths, "Source Path", "Library Path", and "External library path". You want to add to the "Source Path" box. There are no crosshairs, use the Folder icon instead.
    • Confirm all dialogs.
    • See a screencast of step 5.
  6. [Optional: Configure Flash Player to trust CS247 examples]:

    as3Glue uses socket connections to talk to a serial proxy. By default, SWF files built by Flex or Flash run in a security sandbox that prevents most socket communication. If you run your files directly in the Flash IDE, you are fine. If you want to execute your files outside the Flash IDE, you have to modify the "Global Flash Player Trust directory" and add project directories where restrictions are not enforced.

    • Run either tools\AddTrustedDirectoryMac.app (os x) or tools\AddTrustedDirectoryWin.vbs (windows) and choose the directory containing the CS247 examples. These scripts try to automatically generate a file with the right contents in you Flash Player Trust directory.
    • If these scripts fail, you'll have to manually edit TrustExampleWin.cfg or TrustExampleMac.cfg and follow directions in the file.
  7. Test your installation: To test whether everything is now installed correctly, go through the following steps:
    1. Start the Arduino IDE.
    2. Make sure your Arduino board is plugged in via USB. Now configure Arduino to use the right serial port. Go to Tools->Serial Port. On the Mac, choose the entry that reads /dev/tty.usbserial-XXXXXXXX. On Windows, it's likely the highest COM port number. To verify, go to Control Panel->System->Hardware->Device manager, open tree node "Ports (COM & LPT)". Look for "USB Serial Port (COMx)". Note the value of x. Select that value in the Arduino list.

    3. Configure the serial proxy (Tools->Network Serial Proxy->...) as follows:

    4. Start the Arduino serial proxy by clicking on this icon:

      (The first  have to unblock the program to give it permission to open a socket. On Mac OSX, you'll get a warning about launching a program downloaded from the internet. Again, you'll have to give permission.)

      In the bottom status bar, you'll now see a speed dropdown box and a black output console. Set the speed to 115200:

      Keep the Arduino environment running in the background - you'll need the network serial proxy to run while you're working in Flash.

    5. Open cs247_examples/test_arduino.fla (not .as) in Flash. Run it (Control->Test Movie on CS4).
    6. In the Flash window, you should see a message like this:
      
      
      At the same time, the Arduino IDE should have printed this: <localhost> connected.

      You are ready to go.

 

Troubleshooting:

 

  1. I can't find /dev/tty.usbserial-XXXXXX on Mac or USB Serial PORT (COMx) on Windows:

    Reason: your FTDI USB driver is not installed correctly. Re-install and reboot to be safe.

  2. I get "Error #2031: Socket Error." when trying to run test_arduino.fla.:

    If you get the following error in the Flash output window

    Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.

    at Untitled_fla::MainTimeline/Untitled_fla::frame1()

    The Flash cannot connect to Arduino's Serial Proxy. Make sure the proxy is running and that the port listed in the Arduino status bar is the same port as in this Flash source code line:

    var arduino:Arduino = new Arduino("127.0.0.1",11100);

  3. I get the Error 1046: Type was not found or was not a compile-time constant:ArduinoEvent. when trying to run test_arduino.fla:

    Reason: Flash cannot find the as3glue library. Please check and repeat step 5. It seems that there might be a bug in Flash CS3 where settings get lost if you do not have an Actionscript file open when you change the settings. Also, if Flash crashes after you changes Preferences, those changes are lost.

  4. I see "Socket connected!" when running test_arduino.fla, but don't see the "Firmware version: 2" message.

    Reason: you either have the wrong firmware running on your Arduino board or something went wrong during the upload of Firmata. In Arduino, select File->Sketchbook->Examples->Library-Firmara->StandardFirmata. Then click the upload button to transfer the firmware onto your board. (Note: Servos will not work with StandardFirmata. Fix later.) You can test your firmware using the network proxy in the IDE  - it prints out all bytes received from Arduino before they are sent on to Flash. When you reset your Arduino, Firmata should send the following bytes:

    <arduino> 0xF9

    <arduino> 0x02

    <arduino> 0x00

    If you don't see these three bytes, then there is a problem with your Firmata firmware. (Also check serial speed)

 

Comments (13)

Matt said

at 2:08 pm on Jan 2, 2009

This is a brilliant Tutorial.

I managed to change the IP to another computer with my Arduino and I can control my electric trains speed.

Please note Standalone flash files will not operate due to Flash socket security issues. I am unaware of a work around at the moment.

Bjoern Hartmann said

at 3:45 pm on Jan 2, 2009

Yes, the Flash socket security policy is quite annoying. There are two ways to get around this problem:
1) You can run a local server that serves a "policy file" on port 843. Adobe is providing reference implementations of such a server in Python and Perl at:
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

2) You can edit your "Flash Player Global Trust directory". The newest version of the as3glue-cs247-examples has some scripts for Windows and Mac OS X that mark directories of your choice as "safe" where permissions are not checked. look in as3glue-cs247-examples/tools

Matt said

at 10:17 am on Jan 5, 2009

Thanks Bjoern.

I have managed to connect now using the Flash Player Global Trust. But this only works for local files. Do you know of anyway of getting it work with files served from a remote host?

uglytv said

at 1:57 pm on Jan 9, 2009

This is the best tutorial arduino/flash online.


Yes Flash Player Global Trust works for local files and is easy to configure,but not work on remote host files, somebody knows a solution for this? i tried to change arduino serialproxy TCP socket 11100 to 843 but i think arduino didn´t permit to change the default serialproxy tcp port.


ZoeVision said

at 1:31 pm on Jan 12, 2009

Hi !

WOW....two days (Weeks?) taskwork, but now Flash connect to Arduino (remote)

But why ?


My Workaround:


1)
Run a local server for the "policy file" on port 843.
=> http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

Policy File (only for testing)


<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<!-- Policy file for socket/xmlsocket://192.168.1.100 -->
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>


Allows to connect every Port and Domain (and IP)


2)
SerProxy listen on Port 5334



3)AS3 Code:


...
function onSocketConnect(e:Object):void {
trace("Socket connected!\n");
}

function onSocketClose(e:Object):void {
trace("Socket closed!\n");
}

var arduino:Arduino = new Arduino();
arduino.connect("192.168.1.100",5334);
arduino.addEventListener(Event.CONNECT,onSocketConnect);
arduino.addEventListener(Event.CLOSE,onSocketClose);
...


But (curious !!!)
Normaly you have to create the Arduino socket like this:

=> var arduino:Arduino = new Arduino("192.168.1.100",5334);


The connection-method are called in Arduino.as (as3Glue)

=> super.connect(_host,_port) (at the contructor);


But this part doesn't work.
I get this error in the Flash output window:

Error #2044: securityError unverarbeitet. text=Error #2048: Verletzung der Sicherheits-Sandbox: http://192.168.1.100/test.swf
kann keine Daten von 127.0.0.1:5334 laden.
at test_fla::MainTimeline/frame1()


If you change your AS3-script to...

var arduino:Arduino = new Arduino();
arduino.connect("192.168.1.100",5334);


...everything works fine. But i dont't know why ?


take a look (German):
http://www.flashhilfe.de/forum/flash-mit-anderen-programmiersprachen/flashcs4-serproxy-arduino-crossdomain-xml-254218-254218.html

Matt said

at 9:23 am on Jan 13, 2009

Well i managed to get it working.

Here is my configuration:


Using flashpolicyd.pl (standalong) with this command line:

sudo perl flashpolicyd.pl --file=../flashpolicy.xml --port=843

The flashpolicy.xml file:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">

<!-- Policy file for xmlsocket://socks.example.com -->
<cross-domain-policy>

<!-- This is a master socket policy file -->
<!-- No other socket policies on the host will be permitted -->
<site-control permitted-cross-domain-policies="master-only"/>

<!-- Instead of setting to-ports="*", administrator's can use ranges and com$
<!-- This will allow access to ports 123, 456, 457 and 458 -->
<allow-access-from domain="*" to-ports="*" />

</cross-domain-policy>

Read about that at: http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html



Then standardfirmata and arduino 13 as above running on my Arduino Duemilenove.

My AS3 code:

var arduino:Arduino = new Arduino("192.168.0.11", 11100);
arduino.addEventListener(Event.CONNECT,onSocketConnect);
arduino.addEventListener(Event.CLOSE,onSocketClose);
arduino.addEventListener(ArduinoEvent.FIRMWARE_VERSION, onReceiveFirmwareVersion);
arduino.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
arduino.addEventListener(ArduinoEvent.ANALOG_DATA, onReceiveAnalogData);

This connect code taken from AS3 Glue Examples test_arduino.as

With that I was able to connect when I ran the remote file on my local network. But I then forwarded the ports (11100 and 843) on my Router to the server which meant it could take connections from the Internet. I tested this from a friends computer on another network.

I hope that is of help

Matt said

at 9:24 am on Jan 13, 2009

I must add that if forwarding ports set the arduino in AS3 to connect to your router WAN IP. (not complicated I know)

Anne-Marie said

at 7:25 pm on Mar 2, 2009

Hi Everyone,
I'm very familiar with Flash and I'm just starting to get my feet wet with Arduino.

I can't seem to get this tutorial working even though I have followed all of the instructions. I do see "Socket connected!" when running test_arduino.fla, but don't see the "Firmware version: 2" message. I do have Firmata 2 uploaded to the board so I'm not sure why it's not reporting the version when I press the reset button on my Duemilanove.

Does anyone have any ideas of why this could be happening? Any help would be appreciated.

Thanks!

Bjoern Hartmann said

at 9:36 am on Mar 3, 2009

Anne-Marie: I look at the updated Troubleshooting instructions step 4 for a test to see if you have the right firmware.

Anne-Marie said

at 2:00 pm on Mar 3, 2009

Thanks Bjoern. I re-uploaded firmata 2 that came with AS3Glue and now I am getting this output:
Socket connected!
Firmware version: 0
Port: 11100

I checked the Troubleshooting instructions for step 4 and I am getting the correct bytes sent from Firmata to Arduino in the network proxy. Any ideas on why it's returning 0?

Thanks in advance for your help.

uglytv said

at 4:38 pm on Apr 23, 2009

any news about remote conection with arduino?

jfmateos said

at 5:16 am on Oct 17, 2009

Thanks to the previous comments I was able to connect remotely to an Arduino using a Flash SWF, but just when the server was Windows XP. I cannot make it work in a server using Windows Vista.
Does anybody have success installing the python server for the port 843 in Windows Vista?
Best regards from Madrid.

technodai said

at 10:55 am on Apr 1, 2010

I'm having the same problem as Anne-Marie. I have reinstalled Firmata2, tried various different versions, baud rates and configured the serproxy settings. Nevertheless I still get firmware version 0 and no usable data when tested with accell_ball or otherwise.

Does anybody have a solution?

You don't have permission to comment on this page.