jQuery and ExternallInterface

It seems to be that ExternalInterface will not work if the flash file is referenced with jQuery. Which is odd because the jQuery wil translate to the javascript function getElementById. However the following code gave javascript errors that the function send2Flash could not be found.


if( $("#debaak").length > 0 )
{
$("#debaak").send2Flash(str);
}

After discussing this subject we found the following solutions. JQuery returns an object, with the get function it is possible to get any element in the jQuery object returned by the jQuery selector

$("#debaak").get(0).send2Flash(str);
or
$("#debaak")[0].send2Flash(str);

The javascript way also works perfectly whithout any errors.


if (document.getElementById)
{
flashMovie = document.getElementById("debaak");
}

if (flashMovie)
{
flashMovie.send2Flash(str);
}

Below you can find the necessary code for flash.


public function Main()
{
ExternalInterface.addCallback("send2Flash", callJS);
}
private function callJS(msg)
{
//called from js
trace('call from js:' + msg)
}

Image Carousel: Jquery vs. Flash

I used to build my carousels in flash, but i seemed a good challenge for me to build a nice looking carousel in jQuery. Of course the carousel should have the same functionality as a flash carousel. Thus said the carousel should get all the content from the html itself, include paging, the possibility for some text over the image and have nice transitions.

I searched the web for available plugins and the jQuery Cycle plugin seemed the best start. The only task left for me was finding a way to display text over the images and style the carousel. The result is astonishing and since the content is html it has a lot of advances over flash, SEO, accesibillity and much easier to implement for backend developers. However flash still has to advantage ( or disadvantage ) that it compiles your code which makes it less easy to copy it.

The result and code ( of the jQuery carousel ) can be found here

Reading ArrayCollections in Flash

I always thought that arraycollection were only accessible within Flex. Last week however I needed to access some complex data from a webservice in flash. To access the webservice I used a very handy flash extension, which provided the remoting classes from Flex into flash. The result however contained a ArrayCollections. Luckily I found out that is was perfectly possible to parse the data from the arraycollections into arrays and object. I knew that the result had to contain a Clips Array within each Chapter as you can see in the debugger screenshot. Now in flash I could access these Clips like this

var _chapters_ar:Array = _chapters.list.source;

for( var i:int = 0; i < _chapters_ar.length; i++ )
{
     var _clips_ar:Array =  _chapters_ar[i].Clips.list.source;

     for (var j:int = 0; j < _clips_ar.length; j++)
     {
        ...
}

see screenshot below

debug view in flash