Created
November 17, 2015 00:03
-
-
Save koriner/ae02ed42fdf4eab65b78 to your computer and use it in GitHub Desktop.
Example code for using Application shortcuts with the ForceTouch ANE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
DISTRIQT ForceTouch Extension - Example code for using app shortcuts | |
**/ | |
public function initExtension():void | |
{ | |
if (ForceTouch.isSupported) | |
{ | |
Core.init( APP_KEY ); | |
ForceTouch.init( APP_KEY ); | |
ForceTouch.service.addEventListener( ApplicationShortcutEvent.SHORTCUT_SELECTED, shortcutSelectedHandler, false, 0, true ); | |
} | |
} | |
/** | |
Adds dynamic app shortcuts | |
**/ | |
private function addShortcuts():void | |
{ | |
// Add a custom shortcut item, with no icon | |
var item1:ApplicationShortcut = new ApplicationShortcut("com.distriqt.test.item1", "Item 1 Shortcut", "", ShortcutIconType.None ); | |
ForceTouch.service.addShortcutItem( item1 ); | |
// Add another custom shortcut item with an icon and custom data | |
var item2:ApplicationShortcut = new ApplicationShortcut("com.distriqt.test.item2", "Item 2 Shortcut", "Item subtitle", ShortcutIconType.Alarm, { foo: "bar" } ); | |
ForceTouch.service.addShortcutItem( item2 ); | |
} | |
/** | |
Removes a previously added shortcut | |
**/ | |
private function removeShortcut():void | |
{ | |
ForceTouch.service.removeShortcutItem( "com.distriqt.test.item1" ); | |
} | |
/** | |
Event handler triggered when a user selects an app shortcut | |
**/ | |
private function shortcutSelectedHandler( event:ApplicationShortcutEvent ):void | |
{ | |
trace("Shortcut selected: " + event.item.type); | |
// event.item.userInfo is an object which contains any custom data. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment