A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Preloader movie that will load in external swf

  1. #1
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29

    Preloader movie that will load in external swf

    Greets all,

    I'm trying to create a preloader that will show the progress for loading an external swf movie file. (as opposed to a preloader that shows the progress of the preloader swf itself that is loading the movie that is embedded within it).

    The problem is I am placing an swf on a page that will not display any part of a Flash movie (including the download progress shown by the preloader) until the entire movie is downloaded, regardeless of whether or not there is a preloader built in to that swf movie file.

    I've discovered the only way around this it to have two separate swf's... a preloader swf that loads the second movie swf, (the preloader swf will load first and be displayed before all the movie content is loaded, thereby solving the "no show" problem).

    Although I know how to build a preloader that will import external web content, I do not know how to create one with a loop that will check to see if the entire movie swf is downloaded before it begins to play the movie swf it is downloading.

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    hi....

    your current problem can (sorta0 be fixed by exporting your preloader movieClip in the firstFrame for actionscript.. so it loads and is ready before the rest of the content.. this will cut most of the 'lag' off..

    however I still your new request is the BEST method.. and the ONLY method I use.

    in my footer are several links on how to make your own preloader. (and a few links to some preloader components I built)

    basically to load an external.swf you need to load it into a target or a _level.
    (a target is nothing more than a blank/empty movieClip....often referred to as a containerClip..)

    here is an example:

    containerClip.loadMovie("some.swf");

    have to make sure you have a movieClip on the stage with the instance name of 'containerClip' then.

    the preloader really just checks the 'containerClip'.. (over and over).. to see the totalBytes (.swf) you are loading into it.. and how much of it has currently loaded....


    my preloader components I created are very easy to use.. drag one to the stage.. set the .swf you want to load... set the targetClip you want to load it into..



    NOW.. that being said.. you should learn to code your own.. and using loadMovie() is the older way.. using a movieClipLoader() instance is by far much better..

    in my footer is another link called clipLoader.. read it.. they are VERY easy to use.. and fllow the same ideas summarized above.. just gives you better/easier control on getting the progress of the content being loaded....as well as telling you when the content has started or finished loading...etc..

  3. #3
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Thanks for the replies. Here is the current code I'm using for the preloader:

    var myMCL:MovieClipLoader = new MovieClipLoader();
    var myListener:Object = new Object();

    myMCL.addListener(myListener);

    myListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
    var loaded:Number = Math.round((bytesLoaded/bytesTotal) * 100);
    progressBar.gotoAndStop(loaded);
    }

    myListener.onLoadInit = function (target_mc:MovieClip) {
    progressBar._visible = false;
    }

    myListener.onLoadStart = function (target_mc:MovieClip) {
    progressBar._visible = true;
    }

    myMCL.loadClip("http://www.myURL.com/file.swf ", "container");




    This preloader works fine and simply animates a 100 frame animation on the stage while loading my target_mc movie file into the MC container.

    There are two problems.

    The first problem is that there is nothing incorporated to check to see if all of target_mc is downloaded and only then start playing the movie clip. The reason I know this is because, when viewing my swf on a webpage, I will see the frames of the movie loading at the same time I am seeing the progress bar animating on the stage. If I'm creating an swf with a preloader that does not load an external swf, but rather is totally self contained, there is no problem. For example, the following code:



    bytesLoaded = Math.round(this.getBytesLoaded());

    bytesTotal = Math.round(this.getBytesTotal());

    getPercent = bytesLoaded/bytes_total;

    this.progressBar._width = getPercent*100;

    this.loadText = Math.round(getPercent*100)+"%";

    if (bytesLoaded == bytesTotal) {
    this.gotoAndPlay(3);
    }


    On frame 2 of my actions I would simply have an action to send the playhead back to frame 1. And on frame 3 of my actions would be the start of my video embedded in the timeline or in a MC. On the stage would simply be the progressBar. I've tried this and it works.



    Because of the above problem, the second problem is that I am embedding these swf files on a "social networking" site. Well this site has an odd habit of not showing any of the movie clip until the entire swf is downloaded. What this means is that viewers cannot see the progress bar or the downloading progress of the preloader. There is just a square hole (or nothing) until the entire movie clip is loaded and only then can they see it, which defeats the whole purpose of the preloader. My theory is that if I create a separate swf preloader to load the movie clip swf, at least this site will then be able to display the preloader swf (and therefore the progress) while the movie clip is loading.

    However, I do not know how to create a preloader (I am a novice) that will load an external swf and also do an if/else check to start the movie clip only when the entire thing is loaded.

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    ok...well first things is..

    C: The first problem is that there is nothing incorporated to check to see if all of target_mc is downloaded and only then start playing the movie clip.

    A: this is done on the onInit part of the callbacks.. onInit means once the clip has finished loading and is ready to be manipulated or played..etc

    myListener.onLoadInit = function (target_mc:MovieClip) {
    progressBar._visible = false;
    }

    sameplace you turn OFF you preloader..is where you would START playing your .swf

    so if you loaded your external.swf into a movieClip called: containerClip
    (ie: myMCL.loadClip("external1.swf", "containerClip")

    you would just say containerClip (which now really your external.swf loaded into it) containerClip.play();

    this will start your external.swf going..


    and reading on.. your number 2 question will also be fixed...

    read up on the clipLoader() class.. just hit F1 while in Flash and search for it..

  5. #5
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Seem I've been trying it all. Is there a visibility property for a MovieClip symbol? If so I could just make 'container' invisible until onLoadComplete (I think).

    I'm using two files: preloader.swf which is loading in banner_vid.swf.

    It's crazy because I can watch the video frames loading as the progressBar is moving. On any "normal" website I don't think this would happen. But like I said this site is weird. It there any way I could keep my 'container' symbol invisible until download completes?

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    if your loading in a video..it is probably playing because it is streaming...

    and yes.. LOOK at the code you are already using... there IS a _visible property

    progressBar._visible = false;

    same thing for any movieClip.. not just the progressBar movieClip

  7. #7
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    LOL I've been looking at the code so hard I already took two advil over an hour ago. I realize this is a learning experience and I'm learning which is good.

    I am appreciating all the advice and pointers and I imagine the idea would be something like:

    onLoadStart container._visibility = false;

    and

    onLoadComplete container._visibility = true;

    Now I just have to try 40 ways till sunday until I get the syntax right

  8. #8
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    follow the syntax from above.. its the exact same.. as a mater of fact just USE that.. and add in another line to turn the things on/off

    PHP Code:
    myListener.onLoadInit = function (target_mc:MovieClip) {
    progressBar._visible false;
    container._visible true;
    }

    myListener.onLoadStart = function (target_mc:MovieClip) {
    progressBar._visible true;
    container._visible false;


  9. #9
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    HAHAHAHA!!! I got it! Here's what I added:


    // Hide movieClip during load
    myListener.onLoadStart = function (target_mc:MovieClip) {
    container._visible = false;
    }

    // Reveal movieClip after load
    myListener.onLoadComplete = function (target_mc:MovieClip) {
    container._visible = true;
    }


    I had little idea what I was doing and went through a few iterations but it worked!

  10. #10
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Thanks whispers... I guess when I heard the sound of hooves in the forest, I was imagining a zebra instead of a horse. IOW I thought it would be more complicated. BTW I swear that, with a bit of difficulty, I finally "conjured up" that working code just b4 you posted the answer hehe But thanks very much! Your code is of course much more simplified.

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    heres a tip..and another little lesson..

    1.) using onComplete may work this time. but if you need to get the dimensions or manipulate the containerClip in some fashion..you wont be able to. You need to wait until the clip has fully initialized before you can 'talk to it'.. so using onInit is aways more stable..


    2.) if you see the callback functions:
    (example)
    myListener.onLoadComplete = function (target_mc:MovieClip)

    in the paramaters you define target_mc... this is the target that is initiating the callback..

    so you could have done this... without using the container name:

    // Reveal movieClip after load
    myListener.onLoadInit = function (target_mc:MovieClip) {
    target_mc._visible = true;
    }

    because you have already registered this listener object to the 'container' clip.... this is would be the target_mc...

  12. #12
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Thanks again whispers. What you're telling me is right now about 50% intelligible and 50% greek to me, but I get the jist and will understand it better soon I will also change the function to Init instead of Complete and keep studying up with the Flash help and Actionscript DVDs.

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