A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: Hopefully last Preloader question

  1. #1
    Member
    Join Date
    Mar 2003
    Posts
    66

    Hopefully last Preloader question

    Hello...I am using MX and I have compoments in all my swf's that I want to load into main swf. I found a preloader to use that is placed in its own swf and loads my main swf into it.

    My problem is I need a preloader that will load my swf's into my main movie. I need a preloader that will work in MX that loads my swf's that have components that are in the first frame.

    Can anyone suggest a good preloader for external swf's that can be used in MX?

  2. #2
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Here's a concept, based on how flash streams and how preloaders work. It doesn't matter if there is a gigabyte of content in the first frame, the preloader animation will start as soon as the loadMovie button is pressed and stop when the content is loaded. Check out this real simple ten minute job.

    http://www.flashbax.com/nopreload.html

    How it works, is the animation, [such as it is] is in the main movie. It's a movie clip, with an instance name. It sits on the main stage, and is visible false and stopped in the first frame till the button to load is pressed. Here is the code, in F6, all in the frame 1 actions layer:

    Code:
    _root.lodAni._visible = 0; //makes the animation invisible
    
    _root.butt.onPress = function(){
    	_root.lodAni._visible = 1; //makes the animation visible
    	_root.lodAni.play(); //starts it playing
    }
    
    _root.butt.onRelease = function(){
    	_root.holder.loadMovie("slider3b.swf"); //loads the external movie in the holder mt clip
    }
    So, this starts the preloader animation clip, and starts the movie loading, the animation is stopped by a frame action in the "loaded" movie. In this case, I put a simple preload code in frame 1 and 2, and the content in frame 3. For this example it wasn't really necessary, cause it only has one frame of content. But, if there were more, this loader would hold off showing it till the whole thing, or part of it was loaded. The code to shut off the loader animation is in frame 3:

    Code:
    stop();
    
    _root.lodAni.gotoAndStop(1);
    _root.lodAni._visible = 0;
    The preloader in frame one looks like this:

    Code:
    ifFrameLoaded (3)
    	this.gotoAndPlay(3);
    In frame 2 is just a gotoAndPlay(1);

    I'm sure anyone can see the beauty of this. Even the smallest normal type preloader is about 3K. You don't need it now, and you can load a ton of different movies into the main using the one animation.

    Did I mention that it doesn't matter anymore if you have components which must load in the first frame. The preloader will start right now and stop when the movie appears.
    Last edited by iaskwhy; 03-27-2003 at 01:41 AM.

  3. #3
    Member
    Join Date
    Mar 2003
    Posts
    66
    Let me see if I have this....

    I put the first bit of code in frame 1 of my main movie swf.
    Then I put the other code in frame 1, 2, 3 of all my other swf's that I want to load into my main swf?

    When I press my link buttons on my main swf to load my other swf's into my main swf....they will preload with no hesitation on the preloader, it will show loading from the beginning?

  4. #4
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    You saw it work. It has limitations. You can't have a text field or a grow bar that is run from any load data. But then who cares, it's the animation that counts, and this definately does not have to load the first frame of anything before it starts. Hasn't that been the big problem till now?

  5. #5
    Member
    Join Date
    Mar 2003
    Posts
    66
    Yes it has...so was I right in understanding how to set it up?

  6. #6
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Ah, yes, you need the animation movie clip...



    Hell, here's the fla's for both movies. Rip them apart and you'll see how simple this is.
    Attached Files Attached Files

  7. #7
    Member
    Join Date
    Mar 2003
    Posts
    66
    I guess my confusion comes from on your file you have the actionscript to load the swf on the actions layer, not on your button.

    What if I have lets say 6 link buttons that I want to load seperate swf's into my main movie? Where do I put the actionscript for all 6 different swf's, as before I would ad the actionscript to the button.
    Am I making sense?

  8. #8
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Perfect sense. My code is for Flash 6 only. I prefer doing it that way, cause it's simpler for me and allows me to use movie clips as buttons. This code:

    _root.butt.onPress = function(){
    _root.lodAni._visible = 1; //makes the animation visible
    _root.lodAni.play(); //starts it playing
    }

    Is in a frame, cause I used an instance name on a movie clip, not a real button symbol. The instance name is 'butt'. So if your using real buttons, then it would go like this:

    on(press){
    _root.lodAni._visible = 1; //makes the animation visible
    _root.lodAni.play(); //starts it playing
    }

    Either way, all you want to do is trip the loading animation and make it visible.

  9. #9
    Member
    Join Date
    Mar 2003
    Posts
    66
    I am sorry to keep going over this...I am just a lttle fried from a long day and just am having a hard time grasping this.

    So, if I use mc(with buttons inside), where do I put the action for all 6 swf's I want to load. I see you did it in the frame, but what if I want to load different link sections when the mc is released?

    If I am planning on using your method of using mc with instance names, where do I put the action for the 6 swf's I want to load?

    And if I am using buttons(not mc with instance) where do I put the actions for the 6 linked swf's to load in my main swf?

    Again I apologize and I hope I am making some sense,its just I have been trying to find a preloader to use in mx that will load external swf's without the damn delay!

  10. #10
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    If you use buttons, use the same code on each button for the press part. The same place you put it for any button, on the button. For the release part, of course you want to change the name of the swf, but the rest stays the same. You just keep loading new movies into the empty clip, 'holder'.

    If you want to use movie clip buttons, like I did, just put the code in the actions layer, on frame 1. Just stack them up. I have some button codes in the main movie on my WWW site that are 154 lines long. Just keep stacking them up, like this:

    Code:
    _root.lodAni._visible = 0; //makes the animation invisible
    
    _root.butt.onPress = function(){
    	_root.lodAni._visible = 1; //makes the animation visible
    	_root.lodAni.play(); //starts it playing
    }
    
    _root.butt.onRelease = function(){
    	_root.holder.loadMovie("slider3b.swf"); //loads the external movie in the holder mt clip
    }
    
    _root.lodAni._visible = 0; //makes the animation invisible
    
    _root.butt1.onPress = function(){
    	_root.lodAni._visible = 1; //makes the animation visible
    	_root.lodAni.play(); //starts it playing
    }
    
    _root.butt1.onRelease = function(){
    	_root.holder.loadMovie("slider4b.swf"); //loads the external movie in the holder mt clip
    }
    
    _root.lodAni._visible = 0; //makes the animation invisible
    
    _root.butt2.onPress = function(){
    	_root.lodAni._visible = 1; //makes the animation visible
    	_root.lodAni.play(); //starts it playing
    }
    
    _root.butt2.onRelease = function(){
    	_root.holder.loadMovie("slider5b.swf"); //loads the external movie in the holder mt clip
    }
    Use different instance names for the buttons.

  11. #11
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    OK, here's basically the same movie, but with 6 buttons, loading 6 different movies. Same button symbol, [which is a mc], same code, except for the instance name of the button and the name of the swf to load. Each one kicks in the loader animation clip when the button is pressed. Each button starts loading it's swf on release. Each swf has the same code in the three frames, telling the loader animation to shut off and get out of sight, once the movie is loaded.

    http://www.flashbax.com/nopreload.html

    The second time through they load very fast because you've got the movies cached.

  12. #12
    Member
    Join Date
    Mar 2003
    Posts
    66
    Thanks so much for being patient with me...it makes sense now and I am going to try and incorporate it today on the site I am building.

    I really appreciate the indepth description you went into for me, I am sure it can be frustrating for you guys when you get newbies (like me) that don't understand and need that little extra push!

    Thanks again!

  13. #13
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Sure, no problem. Maybe I should have explained a little better about preloaders and loading. The way it works is that when a flash movie is called, it will start to load frame 1, and then it will play frame 1, as soon as it is loaded, while frame 2 loads in the background. It'll naturally do both at once.

    To get the best perspective for this, open a large file fla. Do a test movie, then while in that view, go to the top and press View/Streaming Graph, and View/Bandwidth Profiler. Then hit Ctrl + Enter again. You will see your file start to load, it looks like a green line. The 'playhead' for the movie is the little carat there in frame 1. The spike in the lines to the right are the bytes in each frame. The green line will stop to load any spike above the bottom horizontal line, while the playhead won't. It'll only stop for the front of the green line. That means your movie will stop too, if those frames aren't loaded before the playhead gets there.

    So, what a preloader does, is stop that playhead, or rather makes it bounce between frame 2 and 1, while the green line gets a good head start. The playhead will only advance as fast as the fps set for the movie, while the green line will go as fast as the connection lets the data in. In reality, you don't need to preload all the movie, but only enough of it to let the green get far enough ahead that the carat has no chance of catching up. This View/ display will help you determine that.

    The problem with components, sounds, embedded fonts, and a few other things is that flash forces them to load in frame 1. Since most preloaders work from frame 1, and frame 1 will not show anything until it is fully loaded, it's been a real problem. Now, the animation can be in the main movie and it doesn't matter what is in frame 1 of the loaded movie, cause there will be something to see while it loads.

  14. #14
    Member
    Join Date
    Mar 2003
    Posts
    66
    Thanks! One last question...I have to use buttons because I am relying on them for other action as well (scrolling slide show).

    On the buttons I have the code to control the slide show, now, for each button I add, agter the action for the scrolling slide show:

    _root.(button instance name).onPress = function(){
    _root.loadAni._visible =1;
    _root.loadAni.play();
    }

    _root.(button instance name).onRelease = function(){
    _root.(Empty MC instance name).loadMovie("moviename.swf");
    }

    Does this look correct?

  15. #15
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Yes, but you don't need to make separate calls if your doing other things with the same button at the same time, just add the lines after the first function call. A forinstance:

    _root.(button instance name).onRelease = function(){
    _root.(Empty MC instance name).loadMovie("moviename.swf");
    _root.EmptyMCinstancename._x = 120;
    _root.EmptyMCinstancename._y = 100;
    _root.EmptyMCinstancename._xscale = 80;
    _root.EmptyMCinstancename._yscale = 80;
    }

    And don't use ( ) or spaces before the = sign.

  16. #16
    Member
    Join Date
    Mar 2003
    Posts
    66
    Here is the action script for a button on my main swf:

    on (rollOver) {
    with (mySlider) {
    picno=5
    }
    with (mySlider2) {
    picno=5;
    }
    }


    Now I want it to use the function you gave me, so I add:

    _root.(button instance name).onRelease = function(){
    _root.(Empty MC instance name).loadMovie("moviename.swf");
    _root.EmptyMCinstancename._x = 120;
    _root.EmptyMCinstancename._y = 100;
    _root.EmptyMCinstancename._xscale = 80;
    _root.EmptyMCinstancename._yscale = 80;
    }

    I have to give the xy location of my EmptyMC? And the xy scale?

  17. #17
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    No, you don't have to give the xy, I just used that as an example that you 'could' if you want to add other parameters to the function.

  18. #18
    Member
    Join Date
    Mar 2003
    Posts
    66
    Oh ok...thanks....well this should be it then?:

    on (rollOver) {
    with (mySlider) {
    picno=5
    }
    with (mySlider2) {
    picno=5;
    }
    }
    _root.(button instance name).onRelease = function(){
    _root.(Empty MC instance name).loadMovie("moviename.swf");

    }


    And this goes in my frame of main swf:

    _root.(instance of animation)._visible = 0;
    _root.(button instance name).on press = function(){
    _root.(instance of animation)._visible = 1;
    _root.(instance of animation).play();
    }

  19. #19
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    No, not quite. This:

    on (rollOver) {
    with (mySlider) {
    picno=5
    }
    with (mySlider2) {
    picno=5;
    }
    }
    Has to go 'ON' the button. Meaning you click the button on the stage, then add that in the actions panel. It won't work otherwise.

    And this:

    _root.(button instance name).onRelease = function(){
    _root.(Empty MC instance name).loadMovie("moviename.swf");

    }
    Must go in a frame. It won't work if you try and add it like you did the one above, meaning "ON' the button. And this:

    _root.(instance of animation)._visible = 0;
    _root.(button instance name).onPress = function(){
    _root.(instance of animation)._visible = 1;
    _root.(instance of animation).play();
    }

    Also goes in a frame, the same frame and below the frame code above.

    You could change that button code to frame code like this:

    _root.button instance name.onRollOver = function() {
    with (mySlider) {
    picno=5
    }
    with (mySlider2) {
    picno=5;
    }
    }
    Last edited by iaskwhy; 03-27-2003 at 04:35 PM.

  20. #20

    Preloader

    This is a great post curtesy of IASKWHY and I have decided to use the example in it for my own project. But I am experiencing one problem with it.

    Here goes:
    Everything seems to work perfectly for me except the Load Animation MC does not play, it simply stays on one frame and waits for the external swf to load then as programmed stops and disappears.

    Any Predictions why? Take a look at this post, it is a great concept.

    Thanks!

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