0

I've an asp.net website, where i have a flash object embedded. Flash object have some functions registered via ExternalInterface, so it should be accessible from JavaScript. And they are, but only when i call it when site completely loaded and i trigger some events (click etc) But when i try to access any of this function from the script block, i have an error that i call an underfined function.

This script placed at the end of document, at this moment flashGame object not underfinded, but his functions is underfined.

<script type="text/javascript">
            var flashObj = document.getElementById("flashGame");
            // AdLoaded is underfined at this moment. 
            flashObj.AdLoaded();
            // Also tried this, no luck
            $(document).ready(function () {
                flashObj.AdLoaded();
            });  
</script>

AdLoadedis underfined in both cases. P.S. And if i place a breakpoint at begin of the script it seems then all works ok, function AdLoaded() not underfined. What i miss? Thank in advance.

1 Answer 1

1

You have a ready block but the element is not in the body yet, so getElementById likely returns null,

Try:

$(document).ready(function () {
    var flashObj = document.getElementById("flashGame");  
    flashObj.AdLoaded();
});  

Note, that document.ready is not an indication that the flash finished loading, just that the DOM is ready, so you might have to even do:

$(window).on("load",function () {
    var flashObj = document.getElementById("flashGame");
    flashObj.AdLoaded();
});  
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, i understood where is the problem, so when flash object in DOM is ready but it's external interface not initialized yet, so i get an undefinded value. Thanks Benjamin!

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.