Skip to main content
Participant
August 15, 2011
공지사항

Problem working with InvokeEvent handler

  • August 15, 2011
  • 2 답변들
  • 856 조회

Hi all,

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 InvokeEvents?

Thank you in advance!
-Zach

이 주제는 답변이 닫혔습니다.

2 답변

Adobe Employee
August 24, 2011

Hi Zack,

The InvoleEvent is dispatched when the application is first started and then every time the user tries to open the application while it is already opened. Receiving the Invoke event when you switch between the two files in your application shouldn't trigger this event. You can try to use preventDefault() on the InvokeEvent to cancel it if the "file:///C:/test.html" is already opened.

Can you send us your application just to make a clear view on the exact problem?

Thanks,

--Catalin

ZachBennett작성자
Participant
September 2, 2011

Hi Catalin,

I wish I could send the application over, but I ended up moving things around and I don't have the original code anymore.  The good news is that I solved the problem, though!  I just moved things around so that the launch page (now index.html) has some application-level JS and an iframe.  All of my content pages load into the iframe and use parent/child sandbox bridges.

Using the iframe worked out really well for desktop applications, which was all I needed for this project.  I did try to port my HTML/JS/CSS to an iPad app, but iOS doesn't play nice with scrolling iframes, so I may have to rethink the structure for future projects.

Thanks!

chris.campbell
Legend
August 16, 2011

Hi Zach,

I've forwarded this along to our WebKit team for their review.

Chris

ZachBennett작성자
Participant
August 16, 2011

Thanks, Chris - I appreciate it!