Mootools Swiff
Thursday, 19 Mar 2009Updated 19-03-2009: rewritten and extended for more clarity.
I was getting the following errors today while using MooTools' Swiff object. (MooTools version 1.2.1)
It may be wise just to extend your Swiff object right after you construct it:
If you want to execute your function as soon as possible, use the Swiff onload option. However, consider passing your information as parameters in that case.
You can easily check if timing is an issue by calling your flash function from the Firebug console and checking if the function call works or gives you an error.
I was getting the following errors today while using MooTools' Swiff object. (MooTools version 1.2.1)
__flash__argumentsToXML is not definedand
obj.CallFunction is not a functionI'll skip all my frustration with trying to solve this, and skip to the solution.
Swiff != $(Swiff)
The new Swiff constructor will not return a MooTools extended object and as such Swiff.remote calls will not work on them. You will have to call .toElement() on your Swiff object before you can useremote() calls. As such your calls should look like the following Swiff.remote() calls:- Swiff.remote(music_player.toElement(), 'greatFunction');
- Swiff.remote($(music_player), 'greatFunction');
- music_player.toElement.greatFunction();
- $(music_player).greatFunction(); (preferable in my opinion)
It may be wise just to extend your Swiff object right after you construct it:
music_player = new Swiff(....).toElement();or simply
music_player = $(new Swiff(....));in which case you could just use
music_player.greatFunction();
Timing: document.onLoad() vs Swiff.onLoad()
Do not execute your Swiff.remote before your Flash is loaded. In other words, attach this to the load event with:
window.addEvent('load', function() {
});
However, if you create your Swiff object in this document.onload, your ExternalInterface functions are not yet available - you should wait for Flash to be fully loaded.If you want to execute your function as soon as possible, use the Swiff onload option. However, consider passing your information as parameters in that case.
You can easily check if timing is an issue by calling your flash function from the Firebug console and checking if the function call works or gives you an error.



Comments (2)
1. Although Swiff returns the object, this element will NOT have any Element methods applied to it.
2. The $ function on an object/embed tag will only return its reference without further processing.
But it didnt say anything about not working at all ;)
Thanks again!