PlayBook QNXApplication SWIPE_DOWN in a multi platform SWF
A question came up from a developer that was creating a Flex Hero (the 4+ Flex SDK geared towards mobile) mobile application about tapping into the PlayBook’s bezel swipe down event, but also be able to use the SWF on other platforms. PlayBook is a great platform that QNX, a subsidary of RIM, has created PlayBook specific AIR apis and classes.
One of the PlayBook specific API’s is the ability to tap into the bezel event when the user swipes from the top bezel into the tablet screen. As a developer you catch this specific PlayBook event with the following code:
The problem on non-PlayBook platforms is they do not implement the classes that talk from QNXApplication
to the OS to handle this PlayBook specific event. If you run this code on a non-PlayBook platform you will have a VerifyError
that talks about not implementing qnx.pps.PPSChannel
, i have a blog post about how to workaround this for UI testing while on the desktop.
In the use case of this blog post we actually want the functionality of handling the swipe down event to work on the PlayBook and then not throw a runtime VerifyError
on non-PlayBook platforms, basically one SWF that will work across platforms.
Using QNX UI components in a Flex application requires some specialized classes, read more on that topic here. The QNXApplication class and listening for the swipe down event is not trying to mix UI components but just listening for an event. This becomes much easier to integrate this functionality into the Flex application. The example below is in ActionScript but you can just put this in the respective script area of your Flex application.
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.utils.getDefinitionByName;
import qnx.system.QNXApplication;
public class TestCC extends Sprite
{
public function TestCC()
{
super();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
try
{
var c:Class = flash.utils.getDefinitionByName("qnx.system.QNXApplication") as Class;
var q:QNXApplication;
c.qnxApplication.addEventListener("swipeDown", swipeDown);
}
catch(error:Error)
{
graphics.beginFill(0xFF3333, 1);
graphics.drawRect(50, 50, 200, 200);
graphics.endFill();
}
}
protected function swipeDown(event:Event):void
{
graphics.beginFill(0x3333FF, 1);
graphics.drawRect(50, 50, 200, 200);
graphics.endFill();
}
}
}
What the code is doing is checking if the QNXApplication
class is available and then if it is not available goes to the catch code block and does not try and call QNXApplication.qnxApplication
singleton, which throws the VerifyError
. You will notice the instance declaration, but no instantiation, of var q:QNXApplication;
, this is needed to make sure a class reference is compiled into the SWF to test for at runtime. When PlayBook is present the class comes back fine because the qnx-air.swc (extended AIR apis) is present, but on non-PlayBook platforms the classes in qnx-air.swc that QNXApplication
(which we compiled into the SWF) are not present so it throws an error on the getDefinitionByName()
call.
Give it a try and let me know if it works for you.
The other option is to use conditional compile config statements. Some people don’t prefer this way because it complicates building different SWFs for each platform, but its a very viable option.
Pingback: Develop in a multi platform world with FDT « Patrick Kulling