Page 1 of 1

js onload

Posted: Wed Jan 16, 2008 1:33 pm
by tghp2f
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.

Re: js onload

Posted: Thu Jan 17, 2008 7:51 am
by staff
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
 }