1

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!

1 Answer 1

2

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

Oh blimey, how embarrassing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.