PDA

View Full Version : Touch Strip


GuusT
11-23-2006, 04:06 AM
Hey Guys,

I'm kind of new to this forum, and I was wondering if someone could help me out. I'm an industrial designer trying to learn how to use flash as sort of an operating system. Currently I'm trying to emulate a touch strip within flash using the keyboard.

I'm using four buttons: 'g' 'h' 'j' 'k'. Now I want to detect if a user is sliding along the buttons in one direction or the other, and I also want to detect if a user is pressing one button for a longer period of time.

I actually have a working flash movie that does just this, but my code is a mess.

I've attached a zip file with the .fla file in it, anyone care to give me some pointers?

Kind regards,

Guus

blockage
11-23-2006, 04:30 AM
There are quite a few problems with keyUp events in flash. For example if you press down more than one key only the last one down generates an up event. Also, if the window loses focus while the keys are down, no keyUp event is fired.

You'd be better off using an onEnterFrame event handler to detect which keys are actually down...
function onEnterFrame () :Void
{
if ( Key.isDown( 71 ) ) {
// g is down
}
if ( Key.isDown( 72 ) ) {
// h is down
}
if ( Key.isDown( 74 ) ) {
// j is down
}
if ( Key.isDown( 75 ) ) {
// k is down
}
}

GuusT
11-23-2006, 04:54 AM
I'm actually using a windows mobile device with FlashLite 2.1, so that's why I wasn't using an onEnterFrame.

I think my device will act slower if I use this, or am I wrong?

blockage
11-23-2006, 05:03 AM
Polling is never ideal, but as key up is next to useless its the next best option. That said, I've never used Flash Lite so maybe Lite's key events are more robust? I sort of doubt it, but you can easily test it...

GuusT
11-23-2006, 05:09 AM
I've just had access to the testing platform, and this script is actually performing the way it should. So the only thing left is to optimize it for performance.

Do you see any other big mistakes except for my keyUp & keyDown events?

Thanks

blockage
11-23-2006, 05:19 AM
looks fine to me

GuusT
11-23-2006, 05:20 AM
Ok, then I'll continue on from this.

Thanks a lot for the help!