locked
A Newbie question about runtime errors with JS and Silverlight built programs. RRS feed

  • Question

  • I am building buttons (the name of my app is "Button") for web applications and I am having some trouble compiling the code. I am using JavaScript code written for a “Silverlight” program I built in "Expressions Blend".

     

     I begin compiling from the page named “Scene.xaml.js”. The first error I get is:”A runtime error has occurred. Do you wish to Debug".  "Line 26, Error: Syntax Error". I do, so I select "yes".  Then I get pushed to the page named “Default.html.js” and I get "Microsoft JScript runtime error: 'Button' is undefined". I select “Break” and step into the next line of code and I get “Microsoft JScript runtime error: 'handleLoad' is null or not an object”. Then the page loads and I get nothing, a blank explorer page.

     

    I could really use some help. I have been around computers for a good while and have only been programming for about two months. So I would be grateful for the help. I am including both pages of code from my application.

     

    Scene.xaml.js

     

    if (!window.Button)

          window.Button = {};

     

    Button.Scene = function()

    {

    }

     

    Button.Scene.prototype =

    {

          handleLoad: function(control, userContext, rootElement)

          {

         

                this.control = control;

                this.button = this.control.content.FindName("button");

                this.button.cursor = "Hand";

                this.mouseEnter = this.control.content.FindName("mouseEnter");

                this.mouseLeave = this.control.content.FindName("mouseLeave");

                this.mouseDown = this.control.content.FindName("mouseDown");

     

    this.button.addEventListener("MouseEnter",Sys.Silverlight.createDelegate(this, this.buttonMouseEnter));

              this.button.addEventListener("MouseLeave",Sys.Silverlight.createDelegate(this, this.buttonMouseLeave));

              this.button.addEventListener("MouseLeftButtonDown",Sys.Silverlight.createDelegate(this, this.buttonMouseDown));

              this.button.addEventListener("MouseLeftButtonUp",Sys.Silverlight.createDelegate(this, this.buttonMouseUp));

            

            ),

                 

              buttonMouseEnter: function (sender, eventArgs)

              (

                  this.mouseEnter.begin();

              ),

              buttonMouseLeave: function (sender, eventArgs)

              (

                  this.mouseLeave.begin();

              ),

              buttonMouseDown: function (sender, eventArgs)

              (

                  this.mouseDown.begin();

              ),

              buttonMouseUp: function (sender, eventArgs)

              (

                  this.MouseDown.stop();

              )

             

              // Sample event hookup:  

                rootElement.addEventListener("MouseLeftButtonDown", Sys.Silverlight.createDelegate(this, this.handleMouseDown));

          },

         

          // Sample event handler

          handleMouseDown: function(sender, eventArgs)

          {

              // The following line of code shows how to find an element by name and call a method on it.

              // this.control.content.findName("Timeline1").Begin();

          }

    }

     

     

     

    Default.html.js

     

    function createSilverlight()

    {

          var scene = new Button.Scene();// This is the line that keeps getting highlighted when debugging, I guess indicating this is where the issue is?

          Sys.Silverlight.createObjectEx({

                source: "Scene.xaml",

                parentElement: document.getElementById("SilverlightControlHost"),

                id: "SilverlightControl",

                properties: {

                      width: "100%",

                      height: "100%",

                      version: "0.9"

                },

                events: {

                      onLoad: Sys.Silverlight.createDelegate(scene, scene.handleLoad)

                }

          });

    }

     

    if (!window.Sys)

          window.Sys = {};

         

    if (!window.Silverlight)

          window.Silverlight = {};

    Sys.Silverlight.createDelegate = function(instance, method) {

          return function() {

            return method.apply(instance, arguments);

        }

    }

     

    Sunday, June 24, 2007 10:16 AM

Answers

  • Hi,

    I haven't had a chance to walk through your code, but generally one calls "new" only if it is followed by a constructor. if you are still having issues, please post again.

    -Seema

    Thursday, August 30, 2007 4:49 PM

All replies

  • You can try With this.............

     

    if (window.Button == "undefined")

    window.Button = {};

    Button.Scene = function()

    {

    }

    Button.Scene.prototype =

    {

    handleLoad: function(control, userContext, rootElement)

    {

    this.control = control;

    this.button = this.control.content.FindName("button");

    this.button.cursor = "Hand";

    this.mouseEnter = this.control.content.FindName("mouseEnter");

    this.mouseLeave = this.control.content.FindName("mouseLeave");

    this.mouseDown = this.control.content.FindName("mouseDown");

    this.button.addEventListener("MouseEnter",Sys.Silverlight.createDelegate(this, this.buttonMouseEnter));

    this.button.addEventListener("MouseLeave",Sys.Silverlight.createDelegate(this, this.buttonMouseLeave));

    this.button.addEventListener("MouseLeftButtonDown",Sys.Silverlight.createDelegate(this, this.buttonMouseDown));

    this.button.addEventListener("MouseLeftButtonUp",Sys.Silverlight.createDelegate(this, this.buttonMouseUp));

    },

    buttonMouseEnter: function (sender, eventArgs)

    {

    this.mouseEnter.begin();

    },

    buttonMouseLeave: function (sender, eventArgs)

    {

    this.mouseLeave.begin();

    },

    buttonMouseDown: function (sender, eventArgs)

    {

    this.mouseDown.begin();

    },

    buttonMouseUp: function (sender, eventArgs)

    {

    this.MouseDown.stop();

    },

    handleMouseDown: function(sender, eventArgs)

    {

    // The following line of code shows how to find an element by name and call a method on it.

    // this.control.content.findName("Timeline1").Begin();

    }

    // Sample event hookup:

    rootElement.addEventListener("MouseLeftButtonDown", Sys.Silverlight.createDelegate(this, this.handleMouseDown));

    }

     

    function createSilverlight()

    {

    var scene = new Button.Scene();// This is the line that keeps getting highlighted when debugging, I guess indicating this is where the issue is?

    Sys.Silverlight.createObjectEx({

    source: "Scene.xaml",

    parentElement: document.getElementById("SilverlightControlHost"),

    id: "SilverlightControl",

    properties: {

    width: "100%",

    height: "100%",

    version: "0.9"

    },

    events: {

    onLoad: Sys.Silverlight.createDelegate(scene, scene.handleLoad)

    }

    });

    }

    if (!window.Sys)

    window.Sys = {};

    if (!window.Silverlight)

    window.Silverlight = {};

    Sys.Silverlight.createDelegate = function(instance, method) {

    return function() {

    return method.apply(instance, arguments);

    }

    }

     

     

    Thanks,

    Regards,

    Somnath Panja

    Tuesday, June 26, 2007 5:03 AM
  • Hi,

    I haven't had a chance to walk through your code, but generally one calls "new" only if it is followed by a constructor. if you are still having issues, please post again.

    -Seema

    Thursday, August 30, 2007 4:49 PM