PDA

View Full Version : Flash Lite 2.0 softkeys problem


kloucek
06-02-2008, 01:02 PM
Here's my issue:
In one frame (a welcome screen for my app) i assigned left and right softkeys via this code:
fscommand2("SetSoftKeys", "left", "right");
var myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == ExtendedKey.SOFT1) {
// Handle left soft keypress event.
trace ("left pressed");


} else if (Key.getCode() == ExtendedKey.SOFT2) {
// Handle right soft keypress event.
gotoAndStop(2);
}
};
Key.addListener(myListener);

it goes perfectly to the second frame, in which i had the keys reasigned:
fscommand2("resetSoftKeys");
fscommand2("setSoftKeys" , "left" , "right");
var myListener1 = new Object();
myListener1.onKeyDown = function() {
if (Key.getCode() == ExtendedKey.SOFT1) {
// Handle left soft keypress event.
trace ( "send");

} else if (Key.getCode() == ExtendedKey.SOFT2) {
// Handle right soft keypress event.
trace ("help");
}
};
Key.addListener(myListener1);
The output of right softkey is perfect ("help"), but the left softkey outputs both "left pressed" and "send". Now this is only trace, but i'm planning to assign different softkeys to different frames, and that may cause problems.

This kinda makes me stuck, and since deadlines are coming (school project) i would really appreciate some swift help. Thanks

kk_kiran
06-05-2008, 07:22 AM
Hi,

In your application, on the first frame you have added keylistener "myListener" and on the second frame "myListener1". So now both listeners are active. These listeners are stored in an array Key._listeners.

What you can try is modify your code on the first frame as follows:

fscommand2("SetSoftKeys", "left", "right");
var myListener = new Object();
myListener.onKeyDown = function() {
if (Key.getCode() == ExtendedKey.SOFT1) {
// Handle left soft keypress event.
trace ("left pressed");


} else if (Key.getCode() == ExtendedKey.SOFT2) {
// Handle right soft keypress event.

Key.removeListener(myListener);
gotoAndStop(2);
}
};
Key.addListener(myListener);


You need to remove previous listener before adding new one . ( offcourse that depends on your functionality...) hope that will solve your problem

mylee181
03-25-2010, 05:24 PM
stop();
fscommand2("SetSoftKeys", "Previous", "Next");
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == ExtendedKey.SOFT1) {
prevFrame());
} else if (Key.getCode() == ExtendedKey.SOFT2) {
nextFrame();
}
};
Key.addListener(keyListener);

Is there any problem with my AS?
How come there is no response when I click on the button?
Please help

sparkdemon
03-26-2010, 10:38 AM
Here is a application sample with soft-key implemented in each frame with the same listener. please have a look. Let me know if it helps.