views:

154

answers:

2

Hi, I have a page that loads loads of swfs*. I'm loading in them all at the same time, Sequentially which is slowing down the intro animation. Is there a way to load swfs sequentially? Or if not load them on a timer (half a sec would do the trick I think)

*there lots of different dynamically generated Flex graphs so it's not possible to have them all in one.

var swfs = [
                    { url: '/swf/AllBookings.swf', id: "all_bookings", width: 620, height: 365, flashvars: {}, params: {}, attributes: {} },
                    { url: '/swf/AllBookingsByHospital.swf', id: "all_bookings_by_hospital", width: 380, height: 240, flashvars: {}, params: {}, attributes: {} },
                    { url: '/swf/AllBookingsByLanguage.swf', id: "all_bookings_by_language", width: 540, height: 240, flashvars: {}, params: {}, attributes: {} },
                    { url: '/swf/DNAReason.swf', id: "dna_reason", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} },
                    { url: '/swf/DNAInterpreterLanguage.swf', id: "dna_interpreter_language", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} },
                    { url: '/swf/DNAPatientLanguage.swf', id: "dna_patient_language", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} }

                ];

                for (var i = 0; i < swfs.length; i++) {
                    swfobject.embedSWF( swfs[i].url, swfs[i].id, swfs[i].width, swfs[i].height, "9.0.0", false,  swfs[i].flashvars, swfs[i].params, swfs[i].attributes );
                };
A: 

Yes it is possible.

The simplest way is to include the load command for the next swf on the last frame of the last swf - illustrated below.

SWF 1 <------------------|> Load SWF 2

SWF 2 <------------------|> Load SWF 3

SWF 3 ...

Use something like:

_root.YourPlaceholderMC.loadMovie("YourSecondMovie .swf");
Todd Moses
+1  A: 

If you don't have access to the .flas here's acouple of things to try

swfobject.embedSWF takes as its last parameter a callback function which is called on either success or failure docs. I don't know if this is only called when the swf is fully loaded but if that is the case you could use it like this:

var swfs = [
    { url: '/swf/AllBookings.swf', id: "all_bookings", width: 620, height: 365, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/AllBookingsByHospital.swf', id: "all_bookings_by_hospital", width: 380, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/AllBookingsByLanguage.swf', id: "all_bookings_by_language", width: 540, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/DNAReason.swf', id: "dna_reason", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/DNAInterpreterLanguage.swf', id: "dna_interpreter_language", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/DNAPatientLanguage.swf', id: "dna_patient_language", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} }
];

(function() {
    var swf = swfs.shift();
    if( !swf ) return;
    swfobject.embedSWF(
        swf.url,
        swf.id,
        swf.width,
        swf.height,
        "9.0.0",
        false,
        swf.flashvars,
        swf.params,
        swf.attributes,
        arguments.callee //this function will be called again as a callback
   );
})(); //calls itself automatically

If that doesn't work and you want to delay embedding each swf you can do something very similar

var swfs = [
    { url: '/swf/AllBookings.swf', id: "all_bookings", width: 620, height: 365, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/AllBookingsByHospital.swf', id: "all_bookings_by_hospital", width: 380, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/AllBookingsByLanguage.swf', id: "all_bookings_by_language", width: 540, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/DNAReason.swf', id: "dna_reason", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/DNAInterpreterLanguage.swf', id: "dna_interpreter_language", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} },
    { url: '/swf/DNAPatientLanguage.swf', id: "dna_patient_language", width: 300, height: 240, flashvars: {}, params: {}, attributes: {} }
];

(function() {
    var swf = swfs.shift();
    if( !swf ) return;
    swfobject.embedSWF( swf.url, swf.id, swf.width, swf.height, "9.0.0", false,  swf.flashvars, swf.params, swf.attributes );
    setTimeout( arguments.callee, 2000 ); //calls this function again after 2 seconds
})();
meouw