dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Help with preloading mulitple swfs before playing?

  1. #1
    Fo Shizzle nubian niht's Avatar
    Join Date
    Oct 2000
    Posts
    212

    Help with preloading mulitple swfs before playing?

    i've searched the forum and google but didn't really come up on anything solid except for this:
    http://www.flash-creations.com/notes...ic_loadjpg.php

    my as experience is ok but not enough to dissect it in order to do what i want to do.

    i have a few swf's that i'd like to preload before playing a slide show.

    imgMC is the name of an empty mc that's on the stage where the pic_??.swf files will be loaded into.
    what happens is that it will preload the first swf and play, once that swf file is done playing, the slide show it will preload all over again the next swf file.

    can someone please help with a solution on how to preload all of the swfs before if begins the slide show?

    code:
    function proceed () {
    onEnterFrame = function () {
    if (imgMC.getBytesLoaded () != imgMC.getBytesTotal ()) {
    progressbar._xscale = 100 * imgMC.getBytesLoaded () / imgMC.getBytesTotal ();
    } else {
    startSlide ();
    delete onEnterFrame;
    }
    };
    }



    this is how my pic array is set up.

    code:
    pictures = ["pic_1.swf", "pic_2.swf", "pic_3.swf"];



    also can this be done using the MovieClipLoader?

    any help will greatly be appreciated.
    Last edited by nubian niht; 03-14-2008 at 01:15 PM.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Use the MovieClipLoader. It has an onLoadComplete event that you can respond to load completions with. It works great for multiple loads too.
    Basic use is to create a generic object, assign a few functions to it by the same name of the event they are to fire on. Then connect that object to a MovieClipLoader instance as a listener. Then whenever you run loadClip on the MCL instance, it will broadcast events as they happen as your object functions will respond without the need to constantly check bytes.

    Code:
    myListener = new Object();
    myListener.onLoadComplete(targetClip){
      //targetClip is a reference to the movieclip you passed to loadClip();
      //respond to completion code
    }
    myMCL = new MovieClipLoader();
    myMCL.addListener(myListener);
    
    myMCL.loadClip("mySWF.swf", myTargetMovieClip);
    Now in the case of multiple movies, you can call loadClip on myMCL multiple times like in a for loop. Each loading clip will call the same onLoadComplete but it will pass a reference to itself when it does so you can handle it accordingly.

    To answer your question, you could set a global variable equal to the number of swf's you are trying to load. Each time someone broadcasts onLoadComplete, you can have your listener function increment another variable that is tracking the total number of swfs loaded. Simply compare those values each time and run your code for when all things are loaded when that condition is true.

    Code:
    totalSwfs = 5;
    loadedSwfs = 0;
    myListener.onLoadComplete = function(){
      loadedSwfs++;
      if(loadedSwfs == totalSwfs){
        trace("all loading is done");
      }
    }
    geez they're gonna start calling me the mcl evangelist.

  3. #3
    Fo Shizzle nubian niht's Avatar
    Join Date
    Oct 2000
    Posts
    212
    thank you for you reply.

    please bare with me as my AS coding aren't the greatest.
    would it be something like this to preload muliple swfs?

    Code:
    myListener = new Object();
    myListener.onLoadComplete(targetClip){
      //targetClip is a reference to the movieclip you passed to loadClip();
      //respond to completion code
    }
    myMCL = new MovieClipLoader();
    myMCL.addListener(myListener);
    
    myMCL.loadClip("mySWF.swf", "mySWF2.swf", "mySWF3.swf",myTargetMovieClip);

  4. #4
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Hi sorry I didn't reply sooner.
    You would just need to call the loadClip method repeatedly
    for instance:

    Code:
    //places mySwf0.swf through mySwf9.swf into _root.target0 through _root.target9
    for(i=0;i<10;i++){
    myMCL.loadClip("mySwf"+i+".swf", _root["target"+i]);
    }

  5. #5
    Junior Member
    Join Date
    Dec 2005
    Location
    Orchard Park, NY
    Posts
    9
    Hi jAQUAN - I am trying to do the same thing as nubian. I have 5 SWFs that i need to load into my parent movie and then play them sequentially. I tried using your code, but it doesn't seem to be working for me.

    I don't understand how the code works - are all of my SWFs being loaded into the same target movie clip? how do i set it up so that they play one after another? Honestly, i cant even seem to get the MovieClipLoader function to call my SWFs correctly. Am I copying and pasting my code into the FIRST frame of my parent movie? Does any of this code go into the child SWFs?

    Sorry if my questions are ignorant...I'm really lost.

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center