Archive for July, 2008

Netflix Notes: Add a “note to self” next to movies in your queue

To install:

Description:

This happens to me all the time: I decide to add a movie to my Netflix queue — perhaps because it was recommended by a friend, perhaps because I saw a good review, perhaps for some other reason.

Then, months later, I can’t remember why I put it in my queue! To address this problem, I wrote a little Firefox Greasemonkey script called Netflix Notes.

Netflix Notes changes your Netflix queue so that you can add a private “note to self” on each movie in your queue. The main point of this is to remind yourself why you added a particular movie — e.g. because a friend recommended it, you read a good review, and so on.

It only works with the Firefox web browser. If you are using another browser, such as Internet Explorer or Safari, Netflix Notes won’t work for you.

I would love it if Netflix obsoleted my work by integrating this functionality natively into their website! But in the meantime, you can use my program.

30-second demo:

Frequently Asked Questions:

Q: Can other people see my notes?
A: No. The notes are stored on your computer, not out on the Internet. Only someone using your computer can see your notes.

Q: Where, exactly, are the notes stored?
A: They are stored in your Firefox profile. To see them, navigate to about:config, and then type “netflix” into the filter box.

Q: You should store the notes on the Internet! I want to be able to see them from every computer I use.
A: Yes, I would love to add that capability; but I haven’t had a chance to do so yet.

ActionScript’s different ways to convert an object to a string

ActionScript has several different ways to convert an object to a string, and figuring out which one to use can be confusing.  This post compares them, and tries to give you a deeper understanding of what is going on.

  • String(myobj) almost always succeeds; may return "null" or "undefined".  This is usually the behavior you want.
  • "" + myobj is effectively the same as String(myobj), so you can use this instead if you prefer.
  • myobj.toString() calls the toString() member function — in most cases this ends up being equivalent to String(myobj), but if myobj is null or undefined, myobj.toString() will throw an exception.
  • myobj as String will return a string if myobj is a String, but will return null if myobj is of some other type.
  • For objects of type XML or XMLList, don’t forget about myobj.toXMLString().

String(myobj)

This is often the best choice.  If you don’t remember anything else from this post, just remember that String(myobj) is the “safest” way to convert an object to a string.

Although String is a type, String() is also a function.  It isn’t a constructor — it is a regular function.  Its behavior is to take whatever argument you passed it, and convert it to a String.

This function will pretty much always succeed without throwing an exception.  The only case where it will throw an exception is the unlikely case that myobj.toString() gets called and that function throws an exception.

The behavior of String() is formally defined by section 9.8 of the ECMAScript spec.  (Note, this is confusing: When the ECMAScript spec refers to “ToString” or “[[ToString]]”, they are not talking about the toString() function — they are talking about the formal definition of what ECMAScript should do if it needs to convert any object to a string.)

The main thing to remember is that it will always return a string — e.g. if myobj is null, String(myobj) will return the string "null", and if myobj is undefined, String(myobj) will return the string "undefined".  If myobj is a user-defined type, String() will end up calling its toString() function.

"" + myobj (or myobj + "")

This is functionally equivalent to String(myobj).  Because of the rules of ECMAScript’s + operator, "" + myobj will result in String(myobj) being performed on the second argument, and then being concatenated with the empty string.  Concatenation with the empty string is very efficient in the Flash player, so don’t worry about that.

myobj.toString()

This is fine for most cases — it will work on numbers, booleans, user-defined objects, strings, etc. — but if myobj is null or undefined, this will throw an exception. Explicitly saying myobj.toString() means you explicitly want to call the toString() member function of myobj, but if myobj is null or undefined, then of course it can’t have any member functions. 

myobj as String

You won’t use this very often. The "as" operator means, “If the object is already an instance of the specified type, then cast it to the specified type and return it; otherwise, return null.”  So myobj as String will return myobj cast to a String if myobj is already a String, and will return null if myobj is any other type.  In most cases this is not the behavior you are looking for.

myobj.toXMLString()

Don’t forget that if myobj is of type XML or XMLList, then String(myobj) and myobj.toString() will work, but may or may not give the result you wanted; you may want myobj.toXMLString() instead.  See part 5 of Common E4X Pitfalls.