none
Accessing Script Objects from a third party website

    Question

  •  Hi,

    I have to web hosts. One is an apache server (localhost) and the other is the VS 2008 debugging server (the one we get when running a web project).I currently have a php webpage on the apache server, which contains the silverlight object hosted on the VS 2008 server, I also have a accompanying JavaScript file which allows me to access the HTML elements on the php web page. I have an object('bar') declared as a ScriptableObject in the Silverlight 2 application.

     When I click on the php webpage, the Javascript will find the closest element to where I clicked and will give the X Y coordinates of the element. However it seems that I can't access the Scriptable object. I have made the enableHtmlAccess property to true in the Silverlight object. Please help. Any help is much appreciated. :)

     Thank you.

     Nilu

    My code is below:

    Silverlight Code:

     

    [ScriptableType]
    public partial class Page : UserControl
    {
    void Page_Loaded(object sender, RoutedEventArgs e)
    {
    XYPos myObject = new XYPos(); // contains ScriptableMembers X and Y
    HtmlPage.RegisterScriptableObject("myObject", myObject);
    }
    .
    .
    .

    private void getPos(double x, double y)
    {
    HtmlPage.Window.Invoke("getPos", x, y);
    }
    }
      

    JavaScript Code: 

    function getPos(x, y) {
    // get the silverlight object
    var silverlightObj = document.getElementById('silverlightObject');

    silverlightObj.content.myObject.X = getClosestElementX();
    silverlightObj.content.myObject.Y = getClosestElementY();
    }
     
    Friday, August 29, 2008 9:06 AM

Answers

  •  

    Hi ,

    I don't think you will be able to access any managd object direcly like that.But you can create some property and methods which can do same thing.

    Your ultimate aim is to get x and y coordinate of object x so i think that thing you can achieve this way. For that you have to Decorate Sciptable member attribute to your method or property.. 

     

            [ScriptableMember()]

     private void Mname(double x, double y)
      {
         //code goes here  }

    Friday, August 29, 2008 9:34 AM
  •  I realised that you can't actually get the content or the createObject() when in a 3rd party website, so even having scriptable members didn't help me (either property or method). So I had to rely on serializing the results I wanted into a string and send them back to Silverlight.

    If you guys know a better way please let me know. :)

    Saturday, August 30, 2008 6:19 AM

All replies

  •  

    Hi ,

    I don't think you will be able to access any managd object direcly like that.But you can create some property and methods which can do same thing.

    Your ultimate aim is to get x and y coordinate of object x so i think that thing you can achieve this way. For that you have to Decorate Sciptable member attribute to your method or property.. 

     

            [ScriptableMember()]

     private void Mname(double x, double y)
      {
         //code goes here  }

    Friday, August 29, 2008 9:34 AM
  •  Thanks for that :) After some searching I was able to find that it isn't actually possible to grab the ScriptableObject. Which means that what you said the best option. Cheers HarshBardhan!

     Nilu

    Friday, August 29, 2008 9:51 AM
  •  

    Thanks man...You Can expose Properties and method..

    I think you Posted this twice.

    So you can close other one also if it answers...

     

    Friday, August 29, 2008 9:54 AM
  •  I realised that you can't actually get the content or the createObject() when in a 3rd party website, so even having scriptable members didn't help me (either property or method). So I had to rely on serializing the results I wanted into a string and send them back to Silverlight.

    If you guys know a better way please let me know. :)

    Saturday, August 30, 2008 6:19 AM
  • hii... im a nubie in silverlight programming. any body ever try an datagrid on aspx is exported to silverlight datagrid? because im trying to connect MySQL (using NET Connector from MySQL)to silverlight datagrid using ADO, but i dont know why it cannot possible. @tanlith : can you tell me how to run Silverlight on apache? thanks thank you before. i hope you can help my problem. thx.
    Friday, April 24, 2009 1:23 PM
  • Hi Desmondromics,

    I'm not sure about the datagrid question as I haven't actually used datagrids with Silverlight or ASPX. :( In terms of hosting Silverlight applications on apache this link might help you with that. If you want it display Silverlight on a apache hosted website - you need to enable some MIME types; which the article mentions. Hope this helps.

    Cheers,

     Nilu

    Sunday, April 26, 2009 8:46 PM
  • thank you very much! ;) regards ::desMO::
    Monday, April 27, 2009 1:17 AM