• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

FBB - Capture Hardware Back Button Event

New Here ,
Nov 08, 2010 Nov 08, 2010

Copy link to clipboard

Copied

Is it possible to capture the Back Button Event when a user clicks the devices Back Button?

Views

911

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 08, 2010 Nov 08, 2010

Copy link to clipboard

Copied

You can listen to the keyDown event on View and check if the back button was pressed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 08, 2010 Nov 08, 2010

Copy link to clipboard

Copied

Thanks SashaKeith,

I set that up but when I hit the back button it exits out of my app. Is there a way to intercept that action and prevent it from happening?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 08, 2010 Nov 08, 2010

Copy link to clipboard

Copied

You can call preventDefault() on the event.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 08, 2010 Nov 08, 2010

Copy link to clipboard

Copied

Hrmm, sounds simple enough but I guess I didn't get it right. Here is how I coded it:

private function onKeyUp(e:KeyboardEvent):void {      e.preventDefault();      if(e.keyCode == Keyboard.BACK){           if(currentState == "Music"){                toggleMusic();           }      } }

It still exits out of the app...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 10, 2010 Nov 10, 2010

Copy link to clipboard

Copied

LATEST

Try this code:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        keyDown="view1_keyDownHandler(event)">

    <fx:Script>
        <![CDATA[
            protected function view1_keyDownHandler(event:KeyboardEvent):void
            {
                event.preventDefault();
                if (event.keyCode == Keyboard.BACK)
                {
                    lblStatus.text = "Back button pressed";
                }
            }
        ]]>
    </fx:Script>
    <s:Label id="lblStatus" text="Back button not pressed" />

</s:View>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines