How do I manage Adobe AIR InvokeEvent events that are re-dispatched while my program is running?
I'm trying to set up an HTML-based AIR application that allows users to save (and ultimately share) "bookmarks" that point to and launch files on their computers. My entire target audience will be using standard, company-issue laptops that will be pre-loaded with a collection of HTML files that my application is designed to open. All of the laptops will have the same files in the same locations, which simplifies the problem a bit.
My application is made up of 2 HTML pages that the user can navigate between: home.html and page.html. Home.html is the landing page and just has a few buttons on it. Each button on home.html navigates the window to page.html and passes a pageId parameter. page.html uses the pageId parameter to decide which node to parse out from a JSON file stored locally.
My goal is to configure my InvokeEvent event listener to launch locally-stored HTML files from parameters stored in my custom file type. For now, the file type is called .eref and they're just simple text files containing a path to a single HTML page to launch. For example, test.eref contains a single line: "file:///C:/test.html".
I have a script, erefHandler.js, included in both home.html and page.html. erefHandler.js is as follows:
if (air != undefined) {
air.NativeApplication.nativeApplication.addEventListener(air.InvokeEvent.INVOKE, onInvoke);
}
function onInvoke(e) {
if( e.arguments.length == 1 ) {
var file = new air.File(e.arguments);
if(file.exists) {
var fileStream = new air.FileStream();
var byteData = new air.ByteArray();
fileStream.open(file, air.FileMode.READ);
fileStream.readBytes(byteData, 0, file.size);
fileStream.close();
if(byteData.length > 0) {
var s = byteData.readUTFBytes(byteData.length);
var parser=new DOMParser();
var doc=parser.parseFromString(s,"text/plain");
window.open(s, '_blank', 'width=910, height=700, menubar=no, toolbar=no, resizable=yes');
}
}
}
}
This works great when you first double-click test.eref. My problem is that InvokeEvents fired by test.eref are re-dispatched every time any InvokeEvent is dispatched. This appears to occur any time the user navigates between home.html and page.html, since file:///C:/test.html relaunches. In other words, double-clicking test.eref launches my application and launches file:///C:/test.html, as intended, but when navigating to page.html from home.html, the application launches a second instance of file:///C:/test.html (and navigating back to home.html launches a third instance, and so on...).
Can anyone help me figure out how to manage/eliminate these re-dispatched Invok开发者_StackOverflow中文版eEvents?
Thank you in advance!
-Zach
Invoke
is triggered whenever the user does a launchApplication
and the application is not currently open. The only way you can get past this is hide the AIR file based on the arguments/flashvars you pass. Hope this helps.
精彩评论