Fair enough. You have good arguments about not adding custom error handling. How about giving the variable a more descriptive name than "n"? If the variable were named "element", then the error message would say, "element is null", which would be an improvement.
Thanks for pointing out I'm using a seriously outdated version. I'm looking forward to the upgrade! Jean On Jan 21, 1:43 pm, Philip Hutchison <[email protected]> wrote: > Hi Jean > > Thanks for the input. > > First, let me point out that you're using a really outdated version of > SWFObject. The current release is 2.2, which uses a completely re-written > codebase than 1.5. > > Regardless, both editions do not check for the existence of the targeted DOM > element. > > Would it be useful to add error-checking? Probably. I do this all the time > in my own scripts. However, the current practice for every major JavaScript > library/framework (jQuery, MooTools, Dojo, etc.) is to assume that checking > for the existence of the DOM element is the *page developer*'s > responsibility. If you don't know if your element is going to exist (and I > wonder why you wouldn't know), you can write your own check: > > var myElement = document.getElementById("flashcontent"); > if(myElement){ > swfobject.embedSWF("myContent.swf", "flashcontent", "300", "120", > "9.0.0"); > > } > > Two thoughts: > > *Custom error messages > *You're right when you say a custom error message could potentially help a > developer debug their code. However, there are many issues that would arise > from trying to introduce custom error code, including the size of our > codebase (which needs to be as small as possible), and the method of > delivering the message (not everyone has access to console.log via Firebug > or Safari). > > *Silent failure* > Another possibility is silent failure. The code could be edited to simply > exit and not do anything if the DOM element is not found. This could > potentially make debugging even more difficult (why isn't my SWF showing up? > what's going on?) and creates a more lax coding environment. It's better to > allow the error to go through so the developer knows there's something > wrong. > > As for the cryptic error messages you currently see, they're up to the > browser. Different browsers show different errors. But the "n is undefined" > or "n is null" type errors are very well documented in this Google Group > support list. > > - philip > > On Thu, Jan 21, 2010 at 8:06 AM, Jean <[email protected]> wrote: > > Hi, I recently discovered that if the element I pass in for the > > SWFObject to be written into is null, the error I get back is "n is > > null", which had me befuddled for a little while. I figured out what > > was wrong because Firebug showed me the relevant lines of code, but it > > seems that the error message could be changed to be something more > > descriptive, like "element not found: div_flashGoesHere_typo". > > > Example of my code: > > var so = new SWFObject("usindexesview.swf", "usindexesview", "1000", > > "450", "9", "#eeeeee"); > > so.write('div_flashGoesHere_typo'); > > > My page does have a div element called 'div_flashGoesHere' but not one > > called 'div_flashGoesHere_typo'. The error comes on these lines in > > swfobject.js: > > > 125 var n = (typeof elementId == 'string') ? > > document.getElementById(elementId) : elementId; > > 126 n.innerHTML = this.getSWFHTML(); > > > So the error I get is "n is null", which happens on line 126. > > > At the very least, it would help if the variable were renamed > > 'element' or something more descriptive than 'n', but I leave the > > implementation details up to you. :-) > > > Thanks for making a great little script! I'm just hoping I can help > > make it a bit better. > > > Jean > > > -- > > You received this message because you are subscribed to the Google Groups > > "SWFObject" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<swfobject%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/swfobject?hl=en. -- You received this message because you are subscribed to the Google Groups "SWFObject" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/swfobject?hl=en.
