PDA

View Full Version : [FMX] my very simple car..



sicarius
September 7th, 2003, 02:34 AM
Hi there, I'm new to this forum and I'm a complete n00b in Flash and ActionScript,
I'm making this simple flash that allows you to turn on/off the lights of a car. the solution I came up with "works", but on fast computers (actually just any computer) the light blinks, unless you tap the button quickly. (if you look at the code you can see why).

my solution is pretty simple


lights = 0;

if(key.IsDown(key.SPACE) && lights == 0)
{
var color = new Color("car.drasl3");
color.setRGB(0xFFFF00);
lights = 1;
} else if(key.IsDown(key.SPACE) && lights == 1)
{
var color = new Color("car.drasl3");
color.setRGB(0xFFFFFF);
lights = 0;
}



I know there has to be a better solution to this problem, if anyone could help the n00b out would be great.

thx, Sicarius

Digigamer
September 7th, 2003, 02:48 AM
hey man, you put an import password or something on it. I can't view the fla

sicarius
September 7th, 2003, 02:52 AM
sorry, I forgot to disable it, heres the unprotected file (I hope)

Voetsjoeba
September 7th, 2003, 03:06 AM
Here you go :) What was wrong: you tell flash: if lights == 0 then do something and set lights to 1. And after that, you tell flash if lights == 1 then do something and set lights to 0. Since lights has become 1 in the first if statement, the second if statement will be executes too since lights is 1 at that point :)

sicarius
September 7th, 2003, 03:11 AM
Cool, this is much better :thumb: , although I can't understand half of the altered code, but it works and I'm grateful. Hopefully in the near future I can understand what the new code does :).

Voetsjoeba
September 7th, 2003, 03:13 AM
It's not that hard :) I'm sure that if you read through it you'll understand :) And feel free to ask questions :s: