none
"Error calling method on NPObject!" calling SL method via JS

    Question

  • Hi,

    I'm using the following code to call a function inside SL:

    The app loading:

        <object id="silverlight" width="100%" height="100%"
        data="data:application/x-silverlight-2," 
        type="application/x-silverlight-2" >
        <param name="source" value="App.xap"/>
        <param name="onLoad" value="plugInLoaded"/>  
        
        <!-- Display installation image. -->
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" 
            style="text-decoration: none;">
            <img src="http://go.microsoft.com/fwlink/?LinkId=161376" 
                alt="Get Microsoft Silverlight" 
                style="border-style: none"/>
        </a>
    
    </object>


    The pluginLoad() js:

    var control = null;  
    
    function plugInLoaded(sender)  
    {  
        control = sender.getHost();
    }  


    The js function calling the Silverlight method:

    function Answer(answer){
       if(control != null){
           if(answer == "")
           {
               alert("It looks like our server is offline or you're not connected to the internet. Make sure you're connected and try again later.");
               window.location.reload();
           }
           else if (answer == "break!")
           {
               alert("Sorry, something went totally wrong here.");
               window.location.reload();
           }
       control.Content.Page.HandleResult(answer);
       }
       else
           { 
               alert("Error connecting to Silverlight.")
               window.location.reload();
           }
    }
    

    And the silverlight class ( only important snippets ):

     public partial class LoginPage : UserControl
        {
            public LoginPage(string Message)
            {
                InitializeComponent();
                //....
                HtmlPage.RegisterScriptableObject("Page", this);
                //....
            }
    
          //....
    //....
    //....
    
            [ScriptableMemberAttribute]
            public void HandleResult(string answer)
            {
                Game.HandleResult(answer);
            }
    
    //....
    
    
        }


    When I call the Answer function of js now I'm getting the following error in Firefox, Chrome and :

    Error calling method on NPObject!
    control.Content.Page.HandleResult(answer);

    This started spontaneously, but unfortunaly I wasn't able to rever to the point where it worked.
    Can someone tell me what I'm doing wrong? What could make this happen?
    I'm gratefully taking any help or hint!
    Thank you.

    Sincerely,
    Tharuin
    //....
    Saturday, April 30, 2011 5:13 AM

Answers

  • Heyho,

    first of all: thanks for your help!
    I was trying it over and over the last days and wasn't able to fix it. Since I used it as a kind of layer to contact .php sites via ajax because I couldn't find an easy way except HttpRequest to do this, I changed the whole code when I read about WebClient and found out how I can actually get the data with like 4 lines of code.Tongue out


    Wednesday, May 04, 2011 7:01 AM

All replies

  • Hi,

    Error calling method on NPObject!
    control.Content.Page.HandleResult(answer);

    According your description, I created a simple project for testing, but your code works fine for me (Tested in both IE and Chrome).

    So I can't reproduce your problem.

    Would you provide a repro project for us so that we can test and investigate the issue?

    By the way, I think you could check if  your method Game.HandleResult(answer) can work.

     

    Regards

    Wednesday, May 04, 2011 3:50 AM
  • Heyho,

    first of all: thanks for your help!
    I was trying it over and over the last days and wasn't able to fix it. Since I used it as a kind of layer to contact .php sites via ajax because I couldn't find an easy way except HttpRequest to do this, I changed the whole code when I read about WebClient and found out how I can actually get the data with like 4 lines of code.Tongue out


    Wednesday, May 04, 2011 7:01 AM