David Harris's Technology Blog

ColdFusion, Flex, and other stuff...   (and 323,446 hours, 24 mins in to my plan for global domination)

Search:

Calendar:

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Subscribe:

Enter your email address to subscribe to this blog.

Archives By Subject:

Tags:

adobe air ajax cfug coldfusion flash flex frameworks free software fxug general jpgmetadatareader mac off topic opensource papervision spry

Recent Entries:

Top Posts:

Recent Comments:

Top Commenters:

My Links:

RSS:


Adventures in jQuery

The last week or so I've had the pleasure of working deeply with jQuery.

And I mean that, it's been a pleasure.

Once you get used to the 'style' of how it works, it makes sense and has a consistent coding experience.

I've worked mainly with the core and the ui.jquery libraries, with fileupload thrown in. In the mix is also , and they have all played together nicely (so far!)

I've got jQuery adding and removing custom DOM elements on the fly, while updating information on the server, uploading and deleting images and also maintaining the structure of the form so that when it is submitted in the usual "post" manner, the server knows what to do with the data it receives.

So all in all I've had a good experience with it.

Things it has helped me understand is the use of "anonymous Functions" (I think that is what they are called)

EG:

$("#myelement").hide();
will hide the element with the id of "myelement"

now the "hide" method will accept an argument of a function that it will call when it has completed. Commonly called a "callback", so i we had a function like this:

function alertme(){ alert('me'); }
you could call that function when hide was complete like this:
$("#myelement").hide( alertme );
so the function has the name "alertme", so is not anonymous.

To use an anonymous function to do the same thing, this is what you would do:

$("#myelement").hide( function(){ alert('me'); } );

You can also do this in Flex.

eg:

rather than:

addEventListener( "SomeEvent" , someFunction );
You can go:
addEventListener( "someEvent" , function( event: Event): void { [do stuff here] } );
While you can put as much in you function as you like, I did find it makes code a bit hard to read.

One thing that works, but somehow feels wrong, is that the anonymous functions have direct access to the variables declared in the calling function.

eg:

function myFunction()
{

   var someString = "bob";
   $("#myelement").hide( function(){ alert( someString ); } );

}
This seems to be true of both JS and AS. I guess this is because the function itself belongs to the function it is being called in, so has access to the variables called in there...

So all in all I've enjoyed getting to know jQuery, and suspect it's the beginning of a beautiful friendship!

...but, I still prefer Flex!

A Spry/Javascript gotcha!

I am trying out Spry a bit, and this of course means I need to be brushing up on my JavaScript, and XPath to, as Spry uses XPath on the XML datasets...

I run in to a "this works in FireFox, but not IE" issue that turned out to be my understanding of JavaScript, and not Spry.

Read on for more detail...

[More]

Spry 1.5 is preview is live!

The guys working on the Spry Ajax frame work have just released Spry 1.5 Preview

After Ray Camden's presentation to the Auckland CFUG I have been playing with Spry a bit, so will be having a look at this soon!

The features in this release are: - Nested Data Sets - JSON Data Sets - HTML Data Sets - Spry API

The API should be a great help, as I've been using FireBug to inspect the elements and taking guesses at what functions do. Also it's great to see the Data Sets are now more than just XML!

Keep up the good work guys!