webview done loading help

I have a webview in my project and I’m able to get it to load a webpage, but I want to be able to know when the page has finished loading.

I use the following to load the url

call method "URLWithString:" of class "NSURL" with parameter "http://www.urlgoeshere.com"
call method "requestWithURL:" of class "NSURLRequest" with parameter (result)
call method "loadRequest:" of (call method "mainFrame" of (view "TheWeb" of window "TheWindow")) with parameter (result)

I tried to do the following to see when the page is done loading, but it only will tell you if the page is done loading; if there is a embedded movie, swf, etc then the following will still say that its done loading

set isDoneLoadingPage to 1
repeat until isDoneLoadingPage is equal to 0
	set isDoneLoadingPage to call method "isLoading" of (view "TheWeb" of window "TheWindow")
end repeat
log "Done Loading the Page"

I’ve been looking at the webview objective c methods and other info and I found this http://developer.apple.com/documentation/Cocoa/Reference/WebKit/Protocols/WebFrameLoadDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/instm/NSObject/webView:didFinishLoadForFrame:
According to the page, “This method is invoked when a location request for frame has successfully; that is, when all the resources are done loading.” Which I think is what I’m looking for, but I can’t seem to get it to work.

I’d appreciate any help on how to know when all of the resources of a webview page are done loading.
thanks

That method is a delegate method. When your web view loads a page, it sends that message to its delegate (an instance of a controller object somewhere), which in turn executes code contained within its implementation of the corresponding method.

You must implement this in Objective-C, not AppleScript.

Oh, so there’s no way to use the call method function to do that? In that case, if its not too much work, would somebody be kind enough to tell me how to do that with objective c (and is there any way to get the result back to applescript)?

thanks

No, it’s a delegate method. You don’t invoke it explicitly; it is invoked by another object, and you implement it to perform some behaviour when invoked.

http://www.stepwise.com/Articles/Technical/2000-03-03.01.html
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_4.html