Saturday, February 20, 2010

Comparing two objects in jQuery

Had a strange problem in comparing two objects in js. I am dynamically creating a number of divs, adding them to the DOM and also placing them into an array in order to keep tack of what divs are hidden or shown at a given time. Later, I tried to loop through all of the divs and compare them using the === operator but they never returned true -- even though both objects were divs and even showed the same innerHTML.

Anway, a Google search turned up a suggestion to add this function to the jQuery prototype:

$.fn.equals = function(compareTo) {
if (!compareTo || !compareTo.length || this.length!=compareTo.length)
{
return false;
}
for (var i=0; i
if (this[i]!==compareTo[i]) {
return false;
}
}
return true;
}

Problem fixed!

Tuesday, February 16, 2010

More problems with the AS3 Loader Class

I've built an AS3 preloader so a Flash app can preload assets before starting. The app uses a number of Loaders to load about 15 swfs and when the LoaderEvent.INIT is fired it increments the index. When all of the assets have loaded, it starts the app and adds the contents of the Loaders to the display list:

myclip.addChild(MovieClip(myLoader.content);

However, when the app is run from the web occasionally it throws an error that a myLoader.content is null -- so it can't be added to the display list.

I assume that this means that a false INIT event is being fired -- or the player is not always seeing that the content is available to add.

In any event, I wound up setting a Timer that waits 2 seconds before adding the content to the display list. So far this seems to solve the problem for me -- but not the bug....

Saturday, February 6, 2010

Great javascript editor - Aptana Studio

I have been using Dreamweaver for over 10 years and never thought I would need another html code editor -- and ponied up the price for updates every few years. But now that I'm spending increasing time doing javascript development I found that it just wasn't that good for code completion/hinting/documentation etc. After a bit of searching I came across Aptana Studio and absolutely love it. It's built on Eclipse and has everything I could hope for js development -- including being able to install plugins for various frameworks like JQuery, DoJo and more. Plus you can even add a plugin for AIR development.

To install the JQuery plugin just go to:

Help>Install Aptana features>Ajax>JQuery Support

Did I mention that its free?