Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

BlackBerry WebWorks Contributions

Reply
Developer
ashutoshg
Posts: 140
Registered: ‎02-05-2009
My Carrier: Airtel India

(System.event.KEY_BACK, handleBack) Issue in BB 5.0

Hi All,

 

I am using below code

 

try {
    blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);
    function handleBack() {
        alert("handle back button");
        }
    if (blackberry.ui.menu.getMenuItems().length > 0) {
          blackberry.ui.menu.clearMenuItems();
     }
        var item = new blackberry.ui.menu.MenuItem(false, 1, "Exit", OnClickExitButton);
        blackberry.ui.menu.addMenuItem(item);     
} catch (e) {
    alert('exception (addMenus): ' + e.name + '; ' + e.toString());
}

 

i am compiling my application in WW sdk2.3. and running application on deivce. It gives "Refrence Error: handleBack is not defined".

 

Please help me to find out reason. I am stuck here. Not able to add menuitem in application.

 

 

Please use plain text.
Contributor
craigmj
Posts: 13
Registered: ‎10-01-2011
My Carrier: MTN

Re: (System.event.KEY_BACK, handleBack) Issue in BB 5.0

Your problem is only that you're defining the function _after_ you're using it. Change to this:

 

    var handleBack = function () {
        alert("handle back button");
        }

    blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);

 

or even better:

 

    blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, function() { alert('handle back'); });

 

Please use plain text.