Notice: This page contains information for the legacy Phidget21 Library. Phidget21 is out of support. Bugfixes may be considered on a case by case basis. Phidget21 does not support VINT Phidgets, or new USB Phidgets released after 2020. We maintain a selection of legacy devices for sale that are supported in Phidget21. We recommend that new projects be developed against the Phidget22 Library.
|
Language - Flash AS3
Flash, developed by Adobe is used to build dynamic multimedia applications to web pages.
Introduction
If this is your first time working with a Phidget, we suggest starting with the Getting Started page for your specific device. This can be found in the user guide for your device. That page will walk you through installing drivers and libraries for your operating system, and will then bring you back here to use Flash ActionScript specifically.
Flash ActionScript is capable of using Phidgets only over the PhidgetWebService and has support for the complete Phidget API, including events.. We also provide example code in Flash ActionScript for all Phidget devices.
Flash ActionScript can be developed with Windows and Mac OS X. Only ActionScript 3 is supported.
You can compare Flash ActionScript with our other supported languages.
Quick Downloads
Just need the Flash ActionScript documentation, drivers, libraries, and examples? Here they are:
Documentation
Example Code
Library Example Code
Libraries and Drivers
- 32-bit Windows Drivers Installer
- 64-bit Windows Drivers Installer
- Windows Driver and Library Files (Zipped)
- OS X Drivers Installer
Getting started with Flash ActionScript
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:
- Make sure your libraries are properly linked
- Go from source code to a test application as quickly as possible
- Ensure your Phidget is hooked up properly
Instructions are divided up by operating system. Choose:
- Windows 2000 / XP / Vista / 7
- Mac OS X
- Linux (including PhidgetSBC)
Windows(2000/XP/Vista/7)
Description of Library
Flash ActionScript programs on Windows depend on the following files and folders. The installers in the Quick Downloads section put only the phidget21.dll
into your system. You will need to manually put the com
folder onto your system.
phidget21.dll
contains the actual Phidget library, which is used at run-time. By default, it is placed inC:\Windows\System32
.com
folder is the Phidget ActionScript library. It is to be placed in the same directory as your project root.
If you do not want to use our installer, you can download the phidget21.dll
and manually install them where you want; refer to our Manual Installation Instructions.
Flash Professional
Use Our Examples
To run the examples, you first download the examples and unpack them into a folder. To load all projects in Visual Studio, go to File → Open → Project → Solution, and open Visual Studio Phidgets Examples.sln
in the VCpp
folder of the examples.
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project.
This will load all of the examples available for Flash ActionScript, and then you can set your main project to be the one that matches your device. If you aren't sure what the software example for your device is called, check the software object listed in the Getting Started Guide for your Device.
The only thing left to do is to run the examples! Click on Debug → Start Debugging. Please note that the projects, by default try to find the phidget21.h
and phidget21.lib
in the $(SystemDrive)\Program Files\Phidgets
. If you have these files installed in another location, please change the path to the file's location accordingly. Please see the Write Your Own Code section for details.
Once you have the Flash ActionScript examples running, we have a teaching section below to help you follow them.
Write Your Own Code
When you are building a project from scratch, or adding Phidget function calls to an existing project, you'll need to configure your development environment to properly link the Phidget ActionScript library. To begin:
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.
2. Next, select Console Application.
3. Open the project properties window.
4. Navigate to Configuration Properties → C/C++.
5. Add "C:\Program Files\Phidgets"
to the additional directories field. This step will find the phidget21.h
file in the corresponding directory. If the file is placed in another location, please adjust the path to the file's location accordingly.
6. Navigate to Configuration Properties → Linker → Input.
7. Edit the additional dependencies and add "C:\Program Files\Phidgets\phidget21.lib"
. This step will find the phidget21.lib
file in the corresponding directory. If the file is placed in another location, please adjust the path to the file's location accordingly.
8. The project now has access to the Phidget function calls and you are ready to begin coding.
Then, in your code, you will need to include the Phidget ActionScript library:
#include <phidget21.h>
The same teaching section which describes the examples also has further resources for programming your Phidget.
Mac OS X
C/C++ has excellent support on Mac OS X through the gcc compiler.
The first step in using C/C++ on Mac is to install the Phidget C/C++ library. Compile and install them as explained on the getting started guide for your device. Then, the OS - Mac OS X page also describes the different Phidget files, their installed locations, and their roles.
The information we say that we say on the OS - Mac OS X page (i.e. the different files, locations, and roles) should actually be added there |
Use Our Examples
After installing the Phidget C/C++ library for Mac OS X as above, you're ready to download the examples. Afterwards, unzip the file. To run the example code, you'll need to find the source code for your specific device. Then, compile the code under your platform and run it.
The examples assume that the compiled libraries have been set up properly. To set them up on Mac OS X, follow the Getting Started page for your specific device
To compile, link the Phidget C/c++ library, and build an executable binary on Mac OS X, do (for example, depending on the Headers location):
gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers
After using gcc, you will have an executable named example
that you can run.
Write Your Own Code
When writing your code from scratch, you must include a reference to the library header:
#include <phidget21.h>
Then, you would compile your completed C/C++ code the same way as shown in the Use Our Example section above.
To learn how to write your own code for your Phidget, and to learn more about our API, we have a teaching section to help you follow the provided C/C++ examples. Even more help and references are provided from there.
Linux
C/C++ has support on Linux through the gcc compiler.
The first step in using C/C++ on Linux is to install the Phidget libraries. Compile and install them as explained on the main Linux page. That Linux page also describes the different Phidget files, their installed locations, and their roles.
Use Our Examples
After installing the Phidget libraries for Linux as above, you're ready to download and run the examples:
To run the example code, you'll need to download and unpack the examples, and then find the source code for your device. The source file will be named the same as the software object for your device. If you are not sure what the software object for your device is, it can be found in the Software/API section on the Product Page for your device. Then, compile the code under your platform and run it. When compiling, you need to link to the Phidget library.
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with example.c
:
gcc example.c -o example -lphidget21
In this case, example.c
would be the .c file specific to your device. After using gcc, you will have an executable named example
that you can run.
On Linux, if you have not set up your udev rules for USB access, you will need to run the program as root:
sudo ./example
Write Your Own Code
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .c
source code file, you must include a reference to the library header:
#include <phidget21.h>
Then, you would compile your completed C/C++ code the same way as the examples above.
To learn how to write your own code for your Phidget, and to learn more about our API, we have a teaching section to help you follow the provided C/C++ examples and which has resources such as the API reference.
Follow the Examples
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want. This teaching section has resources for you to learn from the examples and write your own.
Next comes our ActionScript API information, with syntax for all of our functions:
- ActionScript API (This is the complete set of functions you have available for all Phidgets)
- Device Specific APIs - The one for your Phidget can be found in its user guide.
To learn the details behind opening, configuring, using, and closing your Phidget, try the General Phidget Programming page. That page also describes using the Phidget in an event-driven manner and in a traditional manner, both of which are available in C/C++.
Example Flow
The Hello World example has this general structure so you can follow along. We also have an in-depth general introduction to writing Phidget code (like open, read data, etc), as well as the {{{3}}} for specific syntax:
// ----- Event and Other Functions ----- Create any Language-Specific Functions (exception handling) Create General Attach, Detach, and Error Handling Functions:
|
In flash ActionScript, you can name these event functions whatever you like. You will then pass them as function pointers to the Phidget library below in the Main Code section. This hooks them into the actual events when they occur. | |
// ----- Main Code -----
Close Device Delete Device
|
Creating a Phidget software object in Flash ActionScript is specific to the Phidget. For a Phidget Spatial, for example, this would involve creating a |
Common Problems and Solutions/Workarounds
Here you can put various frequent problems and our recommended solutions.