js onload

Using Print2Flash Document API
Post Reply
tghp2f
Posts:1
Joined:Wed Jan 16, 2008 12:42 pm
js onload

Post by tghp2f » Wed Jan 16, 2008 1:33 pm

Is there a JS event that allows me to tell when the SWF has been loaded?

something like an onload event?

Basically I am using a custom HTML toolbar that I want to update with total pages, currentzoom, etc... after the swf loads. Currently I am just doing a "setTimeout" and waiting 2 seconds, but if the swf takes longer than 2 seconds the code doesnt work.

Any suggestions are appreciated.

Thanks.

staff
Posts:267
Joined:Sat Dec 15, 2007 4:48 pm

Re: js onload

Post by staff » Thu Jan 17, 2008 7:51 am

There is an onload event for BODY tag but it appears that major browsers may call it even before a SWF file is fully loaded. To get a reliable onLoad event call we recommend using the following technique:
1. Declare the following JavaScript function:

Code: Select all

function checkLoaded(doc) {
    try {
        doc.getCurrentPage()
        clearInterval(doc.checkLoadedInt)
        onLoaded(doc)
    }
    catch(e) {
    }
 }
2. After SWF load code (such as OBJECt tag) insert the following code:

Code: Select all

GetDoc('MyDoc').checkLoadedInt=setInterval("checkLoaded(GetDoc('MyDoc'))",100)
Here MyDoc is the name of your OBJECT tag and GetDoc refers to the function described at http://print2flash.com/help/UsingDocume ... ations.php
3. Then declare your onLoaded event handler with whatever initialization code you need:

Code: Select all

function onLoaded(doc) {
   doc.setCurrentPage(2) 
// Other actions
 }

Post Reply