FLASH CS3 Phidget LED output, beginner

Legacy support with Phidget21
MP6

FLASH CS3 Phidget LED output, beginner

Postby MP6 » Thu Mar 26, 2009 6:53 am

Hello guys,

Im a total beginner :mrgreen: , in working with phidgets
could someone please help me with the following problem:

I have connected the phidgetset on my laptop, with the phidget controll panel running. My goal is to turn on an LED light when entering a frame in flash. (for example; turn on green light in frame 1, turn on red light in frame 2, etc)
I have opened the PhidgetInterfaceKitExample.fla and connected the components. My following step is to turn an LED on, probably i have to use the follwing code:

phid.getOutputState(0,true);


but when playing the flashfile, some errors pop-up and the led did not turn on. For more information about script see below.

What am I doing wrong? :?:

Code: Select all

[size=50]import com.phidgets.*;
import com.phidgets.events.*;

var phid:PhidgetInterfaceKit;

phid = new PhidgetInterfaceKit();

phid.addEventListener(PhidgetEvent.CONNECT,   onConnect);
phid.addEventListener(PhidgetEvent.DISCONNECT, onDisconnect);
phid.addEventListener(PhidgetEvent.DETACH,   onDetach);
phid.addEventListener(PhidgetEvent.ATTACH,   onAttach);
phid.addEventListener(PhidgetErrorEvent.ERROR, onError);
phid.addEventListener(PhidgetDataEvent.INPUT_CHANGE, onInputChange);
phid.addEventListener(PhidgetDataEvent.OUTPUT_CHANGE, onOutputChange);
phid.addEventListener(PhidgetDataEvent.SENSOR_CHANGE, onSensorChange);

phid.open("localhost", 5001);


function onError(evt:PhidgetErrorEvent):void {
   
   trace(evt);
}
function onAttach(evt:PhidgetEvent):void{
   trace(evt);
   phid.getOutputState(0,true);
}
function onDetach(evt:PhidgetEvent):void{
   trace(evt);
}
function onConnect(evt:PhidgetEvent):void{
   trace(evt);

}
function onDisconnect(evt:PhidgetEvent):void{
   trace(evt);
}
function onInputChange(evt:PhidgetDataEvent):void{
   trace(evt);
}
function onOutputChange(evt:PhidgetDataEvent):void{
   trace(evt);
}
function onSensorChange(evt:PhidgetDataEvent):void{
   trace(evt);
}[/size]




User avatar
Patrick
Lead Developer
Posts: 3077
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: FLASH CS3 Phidget LED output, beginner

Postby Patrick » Thu Mar 26, 2009 9:29 am

You'll want to use setOutputState

-Patrick

MP6

Re: FLASH CS3 Phidget LED output, beginner

Postby MP6 » Fri Mar 27, 2009 4:41 am

I have tried that, still this error turns up;

Code: Select all

1046: Type was not found or was not a compile-time constant: PhidgetErrorEvent.
function onError(evt:PhidgetErrorEvent):void {

1046: Type was not found or was not a compile-time constant: PhidgetEvent.
function onAttach(evt:PhidgetEvent):void{

1046: Type was not found or was not a compile-time constant: PhidgetEvent.
function onDetach(evt:PhidgetEvent):void{

etc.....

1046: Type was not found or was not a compile-time constant: PhidgetDataEvent.
function onSensorChange(evt:PhidgetDataEvent):void{

User avatar
Patrick
Lead Developer
Posts: 3077
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: FLASH CS3 Phidget LED output, beginner

Postby Patrick » Fri Mar 27, 2009 9:36 am

have you added the com folder containing the phidget flash library to your project directory?

-Patrick

MP6

Re: FLASH CS3 Phidget LED output, beginner

Postby MP6 » Sat Mar 28, 2009 4:56 am

As I allready mentioned, I am a total beginner.
And yes that, was the problem, I did not copied the com folder into the project directory. The LED is now burning :D

My next step is to lighten up the second LED in frame 2.
But I used this code for the onAttach function, in frame 1.

Code: Select all

function onAttach(evt:PhidgetEvent):void{
   trace(evt);
   phid.getOutputState(0,true);
}


This function will not work on the second frame.
What should I do next?

MP6

Re: FLASH CS3 Phidget LED output, beginner

Postby MP6 » Mon Mar 30, 2009 4:03 am

Hello

I have tried some options, which I though would work out well, but it didn't.
What i did was, creating 5 frames. In frame 1 I have put the following code:

Code: Select all

import com.phidgets.*;
import com.phidgets.events.*;
var phid:PhidgetInterfaceKit;
phid = new PhidgetInterfaceKit();
phid.addEventListener(PhidgetEvent.CONNECT,   onConnect);
phid.addEventListener(PhidgetEvent.DISCONNECT, onDisconnect);
phid.addEventListener(PhidgetEvent.DETACH,   onDetach);
phid.addEventListener(PhidgetEvent.ATTACH,   onAttach);
phid.addEventListener(PhidgetErrorEvent.ERROR, onError);
phid.addEventListener(PhidgetDataEvent.INPUT_CHANGE, onInputChange);
phid.addEventListener(PhidgetDataEvent.OUTPUT_CHANGE, onOutputChange);
phid.addEventListener(PhidgetDataEvent.SENSOR_CHANGE, onSensorChange);
phid.open("localhost", 5001);

function onError(evt:PhidgetErrorEvent):void {
trace(evt);
}
function onAttach(evt:PhidgetEvent):void{
   trace(evt);
}
function onDetach(evt:PhidgetEvent):void{
   trace(evt);
}
function onConnect(evt:PhidgetEvent):void{
   trace(evt);
   if (currentFrame == 1)  phid.setOutputState(1,true);
   if (currentFrame == 2)  phid.setOutputState(0,true);
   if (currentFrame == 3)  phid.setOutputState(1,true);
   if (currentFrame == 4)  phid.setOutputState(2,true);
   if (currentFrame == 5)  phid.setOutputState(0,false);
}
function onDisconnect(evt:PhidgetEvent):void{
   trace(evt);
}


in the folowing frames, I have put the next code:

Code: Select all

stage.addEventListener(PhidgetEvent.Connect ,onConnect);


but this error dissapears.

Code: Select all

TypeError: Error #2007: Parameter type must be non-null.
   at flash.events::EventDispatcher/addEventListener()
   at flash.display::Stage/addEventListener()
   at PhidgetInterfaceKitExample2_fla::MainTimeline/frame2()


Could some one please tell me what i should do??, to turn on/off and LED at a frame (turn on LED1 at frame1, turn LED2 on at frame 2, etc.)??

-MP


Return to “ActionScript 3.0 - Flash CS3 / Flex / AIR”

Who is online

Users browsing this forum: No registered users and 1 guest