problem programming LED in AS3

Legacy support with Phidget21
joyce
Phidgetsian
Posts: 5
Joined: Sat Jan 31, 2015 6:44 pm
Contact:

problem programming LED in AS3

Postby joyce » Sat Jan 31, 2015 7:08 pm

I'm totally lost

I;m using FLash AS3 to

- turn ON a device (either an LED light/cellphone vibrator) for one event (when the mouse rolls over a target)
- to turn it OFF when the mouse rolls OFF the target

I have a Phidgets 8/8/8 Interface and P/N 3052

(I'm testing the software with an LED but want to use a different output to activate the cellphone vibrator)

*****MY CODE********
import com.phidgets.PhidgetInterfaceKit;
import com.phidgets.events.*;

var phid:com.phidgets.PhidgetInterfaceKit;
phid = new PhidgetInterfaceKit();

phid.addEventListener(PhidgetEvent.ATTACH, onAttach);
function onAttach(evt:PhidgetEvent):void{
trace(evt);
}

phid.addEventListener(PhidgetEvent.DETACH, onDetach);
function onDetach(evt:PhidgetEvent):void{
trace(evt);
}

phid.addEventListener(PhidgetEvent.CONNECT, onConnect);
function onConnect(evt:PhidgetEvent):void{
trace(evt);
}

phid.addEventListener(PhidgetEvent.DISCONNECT, onDisconnect);
function onDisconnect(evt:PhidgetEvent):void{
trace(evt);
}

phid.open("localhost", 5001);


var rect:Box = new Box(); // this is the target which must be found

//position the target in a random location
rect.x = Math.round(Math.random() * stage.stageWidth);
rect.y = Math.round(Math.random() * stage.stageHeight);
addChild(rect);

import flash.events.MouseEvent;


//SECTION BELOW INTENDED TO TURN PHIDGET output ON AND OFF
rect.addEventListener(MouseEvent.ROLL_OVER, feedBackA); //mouse is ON the target
rect.addEventListener(MouseEvent.ROLL_OUT, feedBackOffA);//mouse of OFF the target
rect.buttonMode = true;


function feedBackA(event:MouseEvent):void {
trace( " PHIDGET vibration ON YOU ARE OVER THE TARGET ");
//I get trace statement
phid.setOutputState(0,true); //nothing happens. I have an LED in the circuit

}

function feedBackOffA(event:MouseEvent):void {
trace( " PHIDGET vibration off you are NOT over the target ");
phid.setOutputState(0, false);// would this code turn device off if it were on?

}




Thanks in advance

joyce
Phidgetsian
Posts: 5
Joined: Sat Jan 31, 2015 6:44 pm
Contact:

Re: problem programming LED in AS3

Postby joyce » Mon Feb 23, 2015 5:34 pm

For some reason, the main body of the software now works.
the LED turns on when I'm over the target and off when I'm not

However, I also need to control the phidget from a movieclip
like add
phid.setOutputState(0,true);
to the first frame of the movie clip (and turn it off from a later frame)

unfortuinately, none of the phidget identifiers in the parent body are available to the movieclip,

Does anyone know the code which would make the parent phid variables available in the movie (child) ?

Thanks

mattz
Fresh meat
Posts: 1
Joined: Wed Feb 25, 2015 9:42 am
Contact:

Re: problem programming LED in AS3

Postby mattz » Wed Feb 25, 2015 9:47 am

Okay, I haven't touched the Phidgets code or AS3 in like 5 years, but since nobody seems to be responding...

Would this work in the child movieclip?
parent.phid.setOutputState(0,true);

joyce
Phidgetsian
Posts: 5
Joined: Sat Jan 31, 2015 6:44 pm
Contact:

Re: problem programming LED in AS3

Postby joyce » Wed Feb 25, 2015 3:12 pm

Thanks so much for suggesting something

So far it doesn't work
I get this error 1119: Access of possibly undefined property phid through a reference with static type flash.display:DisplayObjectContainer.

joyce
Phidgetsian
Posts: 5
Joined: Sat Jan 31, 2015 6:44 pm
Contact:

Re: problem programming LED in AS3

Postby joyce » Fri Mar 06, 2015 5:19 pm

I've given up trying to program the phidget from a movie clip

I need to repeatedly turn on/off a light at the rate of 1 Hz (500 msec ON, 500 msec OFF)
I've put code on the main timeline and am trying to use loops to perform this function
The code below works without the phid.setOutState(0, true/false);

However, when I add phidget related code, I get an error 1061: Call to a possibly undefined method setOutState through a reference with static type com.phidgets:PhidgetInterfaceKit.

Does anyone know a way to do this?
Thanks

import com.phidgets.PhidgetInterfaceKit;
import com.phidgets.events.*;

var phid:com.phidgets.PhidgetInterfaceKit;

phid = new PhidgetInterfaceKit();
phid.open("localhost", 5001);

phid.addEventListener(PhidgetEvent.ATTACH,onAttach);
function onAttach(evt:PhidgetEvent):void{
trace(evt);

for (var k: int = 0; k< 10; k++) {

for (var i:int = 0; i <500; i ++) {
phid.setOutState(0, true);
trace ("ON");
}
for (var j:int = 500; j < 1000; j++) {
phid.setOutState(0, false);
trace ("OFF");
}
}
}


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

Who is online

Users browsing this forum: No registered users and 1 guest