Morris
Morris

Reputation: 105

Check if Flash object has method from within JavaScript

I am calling an ActionScript object method from within a JavaScript function, however I can't be sure the flash object has that particular method. If the flash object does not supply the method in question I end up with an Error calling method on NPObject!.

How can I check whether the flash object supplies the method in question? I tried to wrap it in a type check like this:

if(typeof flashObj.myfunction() === 'function') {
    //do it
}

But I still end up with:

Error calling method on NPObject!
if(typeof flashObj.myfunction() === 'function') { 
…

Thank you!

Upvotes: 1

Views: 439

Answers (1)

jfriend00
jfriend00

Reputation: 707976

You are actually calling the function in your comparison.

Instead of this:

if(typeof flashObj.myfunction() === 'function') {
    //do it
}

use this:

if(typeof flashObj.myfunction === 'function') {
    //do it
}

Upvotes: 2

Related Questions