Script Error when creating a behavior RRS feed

  • Question

  • I am new, both to web design and Expression Web 4 and am currently working my way through a teach yourself book. All has been ok until I reached behaviors, where I find that trying to create a behavior immediately creates a script error.

    For example, in trying to create a Swap Image Behavior, having selected the original image, as soon as I click on Insert > Swap Image, I get the following message:

    Script Error

    Line: 246

    Char: 2

    Error: Unable to get value of the property 'Clear'. oject is null or undefined.

    Code: 0

    URL: ...................../SwapImg.js

    Any assistance in solving this, in as simple language as possible, would be appreciated. I have tried reparing & re-installing Expression Web to no avail.

    Wednesday, March 30, 2011 10:35 AM

All replies

  • Hmm, the role of properties and methods in javascript can be a little fuzzy sometimes, but it sure appears that here Clear() is a method (function) of the oColumnHeaders object, rather than a property value of the object. In either case, the error message appears to be saying that the object itself hasn't been initialized, and is null or undefined. It stands to reason, then, that its properties and methods would not be available.

    Below are lines 240—252 of the swapimg.js file. Why in the hell they're defining ColumnHeader objects for a swapimg function is beyond the ken of mortals. For that matter, why they require 572 lines of code (?!) to perform a swap function that can literally be done inline is another mystery. It is the reason why no experienced developers actually use these antiquated, bloated, unnecessary behaviors hungover from FrontPage solely for the sake of backward compatibility.

    function initializeForm()
        window.onresize = onResize;
        var oColumnHeaders = theForm.lvImages.ColumnHeaders;
    (l. 246)    oColumnHeaders.Clear();

        var colHeader0 = oColumnHeaders.Add(
                            oColumnHeaders.Count + 1,
                            0 );    

    I don't know what to advise you. I do know that I am not prepared to try to troubleshoot that unimaginably gunky heap of crap code to find out why that error is being thrown. I and others here would advise you that there are far better, more modern, more compact, easier to understand and use methods than those FP throwback behaviors. But, if you want to use them just so you can complete that chapter of the book, fine. Unless someone else wants the job, however, troubleshooting the code is up to you. Sorry.



    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.
    Wednesday, March 30, 2011 3:09 PM
  • Just to add to what Scott says:  Save yourself time and skip the part of the book relating to Behaviors.  Those are holdovers for compatibility with FrontPage sites, and were coded when FP was.  Ignore them. Some are just silly (Javascipt to go to a new page?  Use a link.), some do things that can be done with CSS now, and for those that you still might want to use scripting for, a few lines will do where the Behaviors use reams of code.

    Focus your learning on CSS, and if you need to use dynamic effects, look first on sites that do this with straight CSS, and then to modern scripts.

    Wednesday, March 30, 2011 3:37 PM
  • Hi Peter:

    I don't have an answer for you, but I did receive an email about a month ago from someone having the same problem with the Jump Menu behavior. Her error message was:

    An error has occurred in the script on this page.

    Line: 222 (and 277)
    Char: 2
    Error: Unable to get value of the property 'Clear': object is null or undefined
    Code: 0
    URL: file:///C:/Program%20Files%20(x86)Microsoft%20Expression/web%Web%204/en/behaviors/actions/JmpMenu.js

    Do you want to continue running scripts on this page?

    I have pointed her to this thread to see if she can add anything that might help.

    ~ Kathleen Anderson
    Microsoft MVP - Expression Web
    Spider Web Woman Designs
    Expression Web Resources: http://www.spiderwebwoman.com/xweb/
    Expression Web Wiki: http://expression-web-wiki.com/
    FrontPage Resources: http://www.spiderwebwoman.com/resources/

    Wednesday, March 30, 2011 5:57 PM
  • Thanks to you and Scott for your advice; it was rather the conclusion I had come to and obviously the sensible thing to do. Not liking to be immediately defeated, I thought I would ask in case there was a simple answer; I presume Behaviors must work sometimes at least.
    Friday, April 1, 2011 9:20 PM
  • Thanks, at least I know I am not alone.


    Friday, April 1, 2011 9:23 PM