-
Toggle on/off buttons, digital input from arduino
Hi, i need to get my head around this litte problem.
I hooked up my arduino with flash. I have 6 physic buttons on the arduino which acts as an input to flash.
The input can either be 1 or 0 since it's a digital input. As soon as i run my swf all 6 button sends 0 to flash.
When i press either of them it sends 1 to flash and when I release it it sends 0 again.
like this
buttonOne = a.getDigitalData(1); //button 1
trace(buttonOne)// would give me a 0
//when buttonOne is pressed
trace(buttonOne)// would give me a 1
I would like each button to control the alpha of a Mc. I have 6 mc's each hooked up to a button
mcOne = buttonOne…
When i press buttonOne and it sends a 1 to flash id like 'mcTwo' 'mcThree' 'mcFour' 'mcFive' 'mcSix' to get
alpha 0 and mcOne alpha 1.
Id like it to remain like this even tho i release buttonOne and it becomes a 0.
The same would go for the rest of the mc's and buttons
mcTwo = buttonTwo…
when i press buttonTwo, 'mcOne' 'mcThree' 'mcFour' 'mcFive' 'mcSix' will alla have alpha 0 and mcTwo alpah 1
Best
-
I am not familiar with interfacing the arduino to flash, but If it were a simpleButton in Flash, I would code it like this:
1) create variables for the alpha state of your buttons:
var aBth1:uint = 0;
var aBth2:uint = 0;
var aBth3:uint = 0;
var aBth4:uint = 0;
var aBth5:uint = 0;
var aBth6:uint = 0;
2) you could listen for an event and each time the buttons are pressed, you can change the alpha based on what the variable is.
if(aBth1==0){
mcOne.alpha= 0;
aBth1=1}else{
mcOne.alpha= 1;
aBth1=0}
}
This code will work if it is inside a single event such as CLICK or ROLL_OVER or ROLL_OUT type of event. If it is fired on an ENTER_FRAME type event, then it will behave like you are describing where the change will not stick.
Good Luck!
-
Thanks a lot, i now got the concept!
/C
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|