A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 44

Thread: Need help: load movie clip from library without exporting on frame 1?

  1. #1
    Senior Member
    Join Date
    Mar 2010
    Posts
    157

    Question Need help: load movie clip from library without exporting on frame 1?

    Hello fellow geeks,


    I'm working on a little platformer. Building the preloader now, and it's going to look amazing. Just one little problem: I want to use the character movie clip in the preloader.

    Now many of you might say things like 'just set the character clip to 'export on frame 1', but the problem is that if I do, the character clip will load before the preloader shows, rendering the preloader kind of useless. So here's what I would like to happen:

    1. User somehow opens the .swf.
    2. .swf loads the preloader (white screen) (does not take long)
    3. .swf shows the preloader (preloader is now visible)
    4. .swf loads the character movie clip (preloader still visible)
    5. .swf attaches the character movie clip to the stage (preloader and character clips are now visible)
    6. .swf loads the rest of the game's contents (while preloader and character are still both visible)
    7. if getBytesLoaded() == getBytesTotal() I'll take it form here.

    Surely some of you know if this can be done, and if so, how?
    I'd really appreciate some help on this one.


    Thank you!

    Koen Ahn
    Last edited by koenahn; 09-25-2012 at 04:55 PM. Reason: Safari thinks 'preloader' is a typo.

  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    can you upload the fla?, or at least a fla with preloader and character, that will help.

  3. #3
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Thank you for your reply, Maria Natalia.

    I would upload the flash file, but I highly doubt that would help. My question does not concern a bug or particular case, but a principle of Flash. So although I really appreciate your willingness to help me, I don't think uploading the .fla would make things much easier.

    What would help is if somebody could tell me if it is possible to tell Flash to load certain clips before others, without having to use multiple frames for that.

    Again, thank you.

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I was trying to help you but i got sleepy. Please, i help you tomorrow.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Thank you Angelhdz, I'm looking forward to hearing what you make of this.
    By the way, if you're learning Php (as your footer suggests), you may want to look at sqlzoo.net.

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok im here. Let me try to help you! I have made few things with preloaders
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok this is the trick. Frame 1 will be for prealoading. Frame 2 is the frame where the game starts. Now go to File>Actionscript 2.0 settings and change the Class export frame to 2. On frame 1, put this script:
    Code:
    
    function loading() {
    
    // state variables
    
    var total, loaded, percent;
    
    //we assign the whole movie size in bytes to the "total" variable
    
    
    total = _root.getBytesTotal();
    
    //we assing the total of loaded bytes from the web, to the "loaded"variable 
    
    loaded = _root.getBytesLoaded();
    
    
    
    percent = Math.floor((loaded*100)/total);
    
    //This is for the dynamic textbox that shows the loaded percent from 0% to 100%
    
    prelouderMC.timing = percent;
    
    
    //This will scale the preloader bar until it reaches 100pixels (100%)
    
    	prelouderMC.prelouder._width=percent;
    
    
    
    
    
    
    if (loaded == total) {
    
    //Stop executing this function
    
    clearInterval(PreLoad);
    
    //Remove Preloader movieclip when finish loading
    removeMovieClip(_root.prelouderMC);
    
    //Start Movie
    
    gotoAndStop(2);
    
    
    }
    
    }
    //setInterval is for the loading function to be executed every 1 miliseconds
    //So, our function will check constantly the amount of loaded bytes
    //and it only go to the frame 2 when the preloading ends.
    
    //and the PreLoad variable will tell that our function is running and stop its execution 
    //every 1 second throught clearInterval
    
    
    
    var PreLoad = setInterval(loading, 1);
    
    //Stop in frame 1 until everything loads
    stop(); 
    //Attach the preloader movieclip
    	attachMovie("prelouderMC", "prelouderMC", _root.getNextHighestDepth(), {_x:227,_y:100});
    
    		
    
    	//Attach the maincharacter movieclip
    	
    _root.attachMovie("mainchar", "mainchar", _root.getNextHighestDepth(),{_x:227,_y:150});
    I tested it and it really works. First i get the white screen, then appear the stage color (mine is black) with the preloader and the main character. the preloader begin to load until 100%. Then it redirects to frame 3 where the game starts, and the main character keeps visible. IF you want the main character be attached a little after the preloader, change the whole script to this:

    Code:
    function loading() {
    
    // state variables
    
    var total, loaded, percent;
    
    //we assign the whole movie size in bytes to the "total" variable
    
    
    total = _root.getBytesTotal();
    
    //we assing the total of loaded bytes from the web, to the "loaded"variable 
    
    loaded = _root.getBytesLoaded();
    
    
    
    percent = Math.floor((loaded*100)/total);
    
    //This is for the dynamic textbox that shows the loaded percent from 0% to 100%
    
    prelouderMC.timing = percent;
    
    
    //This will scale the preloader bar until it reaches 100pixels (100%)
    
    	prelouderMC.prelouder._width=percent;
    
    
    
    
    //If the loaded bytes percent is equal to 12%
    if (prelouderMC.timing == 12){
    	mainchar._visible=true;
    }
    
    if (loaded == total) {
    
    //Stop executing this function
    
    clearInterval(PreLoad);
    
    //Remove Preloader movieclip when finish loading
    removeMovieClip(_root.prelouderMC);
    
    //Start Movie
    
    gotoAndStop(2);
    
    
    }
    
    }
    //setInterval is for the loading function to be executed every 1 miliseconds
    //So, our function will check constantly the amount of loaded bytes
    //and it only go to the frame 2 when the preloading ends.
    
    //and the PreLoad variable will tell that our function is running and stop its execution 
    //every 1 second throught clearInterval
    
    
    
    var PreLoad = setInterval(loading, 1);
    
    //Stop in frame 1 until everything loads
    stop(); 
    //Attach the preloader movieclip
    	attachMovie("prelouderMC", "prelouderMC", _root.getNextHighestDepth(), {_x:227,_y:100});
    
    		
    
    	//Attach the maincharacter movieclip
    	
    _root.attachMovie("mainchar", "mainchar", _root.getNextHighestDepth(),{_x:227,_y:150});
    
    mainchar._visible=false;
    Last detail, you need to have the preloader and main character movieclips exported for Actionscript in the library, but with the "Export to frame 2" combobox unchecked.
    Hope that helps.
    Last edited by angelhdz; 09-29-2012 at 10:34 PM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  8. #8
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Wow! This looks great. I had no idea you could export on frame 2 as a setting. I'll try this code out as soon as I get the possibility!
    Thanks for your time, angelhdz!

  9. #9
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Hey Angelhdz,

    I tried doing this:

    On frame 1, I put the preloader.
    On frame 2, I added the character clip (on a different layer, just to be sure the preloader would not have to cross a keyframe—god knows what that might do).
    I set the rest of the contents to export on frame 2.

    The preloader has if(getBytesLoaded() == getBytesTotal){_root.gotoAndStop(2);} in an onEnterFrame loop.

    Whenever I test this, the result is this:

    1. blank screen
    2. preloader on 100% and character clip.


    What am I doing wrong?

  10. #10
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Here's exactly what I would like to happen:


    1. Blank screen. The preloader only is being loaded. Takes short time.

    2. Preloader visible. Character only is being loaded. Preloader shows percentage of not only the character loading, but of both the character, the preloader and the 'rest' being loaded. (e.g. 10 to 60 percent)

    3. Preloader and character visible. 'Rest' is being loaded. Preloader still shows percentage of not only the character loading, but of both the character, the preloader and the 'rest' being loaded. (e.g. 60 to 100 percent)

    4. If everything has been loaded, call on a certain function.


    In this example, the size of the preloader is 10%, the size of the character is 50% and the size of the 'rest' is 40%.

  11. #11
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Did you export the Class to frame 2? File >Actionscript 2.0 settings > Export Frame for classes > type 2

    Why do you want to make a preloader to load the character? Why don't you just attach the character at the same time as the preloader?

    In that case, you just add an "if" statement.
    Code:
    if (percent ==60){  attachMovie("CharacterInstanceName", "CharacterNewName", _root.getNextHighestDepth());  }

    So, 1-white screen 2- preloader shows up and begin to load until 60% 3- at 60%, the character movieclip is attached. 4-the rest will load until 100%, then go to frame 2.

    You have to attach the character movieclip dynamically with attachMovie("CharacterInstanceName", "CharacterNewName", _root.getNextHighestDepth()); not directly on the stage, in order to attach it after the preloader.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  12. #12
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Look at this, if this is what you want.
    http://sofistica2.zzl.org/preload.swf

    Obviously, the white screen won't show up on the web, but it does in the flash player. (At least you want to add a fake white screen at the start of the movie)

    This is what i did. I added an "if" statement to check if the percent is 60% or greater, attach the character movieclip.
    actionscript Code:
    if (percent > 60) {
        //Attach the maincharacter movieclip
       
        if(attached==false){       //IF THE CHAR MOVIECLIP HAVE NOT BEEN ATTACHED
    _root.attachMovie("mainchar", "mainchar", _root.getNextHighestDepth(),{_x:227,_y:150});     //ATTACH IT
    attached=true;  //THE CHAR MOVIECLIP HAVE BEEN ATTACHED THE FIRST TIME, SO, THE NEXT TIME IT WON'T BE ATTACHED.
        }
    };

    Also I added a boolean var, and another "if"statement to avoid the character movieclip being attached multiple times, because the code is inside an onEnterFrame, so it would
    attach it again and again and again.

    This is what we have now:
    1-White screen (only in the flash player preview, not on the web/server)
    2- Preloader attached and loading until %60
    3-at 60%, the character movieclip is attached.
    4- everything keep loading until 100%, then it redirects to frame 2.

    Hope i'm understanding what you want to achieve. Hope this works for you
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  13. #13
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    And remember, you have to test it inside flash, with its built in Test Movie option, then you choose View, Download Settings, choose 56K or DSL, then choose
    Simulate download. This way, you will simulate like if your movie is being loaded from the web in a slow internet connection. Also, if you want to preview it
    on the webpage/server, you have to delete de cache/cookies/browser's offline data, in order to appreciate the preloading proccess. Otherwise, the cached data
    would keep on your system, so, no preloading will show up, and it would go directly to 100% and then to frame 2.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  14. #14
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Hey Angelhdz, sorry about my late reply but I was busy.

    Quote Originally Posted by angelhdz View Post
    Did you export the Class to frame 2? File >Actionscript 2.0 settings > Export Frame for classes > type 2
    Yes, I did. And yes, I have made many preloaders before and I know about the simulated download, thank you.

    Quote Originally Posted by angelhdz View Post
    Why do you want to make a preloader to load the character? Why don't you just attach the character at the same time as the preloader?
    Because the character is a large clip with many animations. The preloader itself is a level with moving platforms that can only be completed if getBytesLoaded() == getBytesTotal().

    Quote Originally Posted by angelhdz View Post
    In that case, you just add an "if" statement.
    Code:
    if (percent ==60){  attachMovie("CharacterInstanceName", "CharacterNewName", _root.getNextHighestDepth());  }
    I really appreciate your eagerness to help me, but please tell me you realise this code is flawed.
    You are assuming that A. we know the player contains 60% of the movie's data and B. that the player has loading priority over the rest. I am sorry to say this, but those things aren't true! The first assumption is fundamentally wrong, since we would have to alter the number ('60%') every time a change is made to the document. Assumption B is probably untrue in this case. To fix these two mistakes we need A. a function that tells us the size of a certain clip compared to the rest of the document and B. a way of telling flash to first load the character clip.

    See my problem here?

  15. #15
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    In that case, i'm not "THE GUY" hehe. I thought it was a "SIMPLE" prealoder, you never mentioned anything about an "ADVANCED" prealoder with a " character is a large clip with many animations. The preloader itself is a level with moving platforms that can only be completed". Obviously the "asumptions" are wrong because everyone who reads your post will also "assume" because you didn't post any script, any .fla. any .swf.

    I'm sure my friends Fruitberd or Nig13 will help you. I don't know anything of "preload specific objects", that's something that i never have seen before in the forums. I'm a flash intermediate scripter, not an advanced scripter. For the next time you require help, be more specific. I finished here.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  16. #16
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Quote Originally Posted by koenahn View Post
    Here's exactly what I would like to happen:


    1. Blank screen. The preloader only is being loaded. Takes short time.

    2. Preloader visible. Character only is being loaded. Preloader shows percentage of not only the character loading, but of both the character, the preloader and the 'rest' being loaded. (e.g. 10 to 60 percent)

    3. Preloader and character visible. 'Rest' is being loaded. Preloader still shows percentage of not only the character loading, but of both the character, the preloader and the 'rest' being loaded. (e.g. 60 to 100 percent)

    4. If everything has been loaded, call on a certain function.


    In this example, the size of the preloader is 10%, the size of the character is 50% and the size of the 'rest' is 40%.
    I didn't assumed anything, you said the character will be attached at 60% and keep loading until 100%. My script is not "flawed", my script did the job that you specified at first. Now you come out with the thing that "the character is huge and with animations" and "the preloader is a level with moving platforms". You didn't mentioned anything about calculating the character's size. My script is not my script, my script is a Preloader script that you will find anywhere on the web. The only thing i added to the script was the
    if (percent > 60) {
    //Attach the maincharacter movieclip

    if(attached==false){ //IF THE CHAR MOVIECLIP HAVE NOT BEEN ATTACHED
    _root.attachMovie("mainchar", "mainchar", _root.getNextHighestDepth(),{_x:227,_y:150}); //ATTACH IT
    attached=true; //THE CHAR MOVIECLIP HAVE BEEN ATTACHED THE FIRST TIME, SO, THE NEXT TIME IT WON'T BE ATTACHED.
    }
    };
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  17. #17
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    I'm sorry we misunderstood each other. Just to clarify, I said: "(e.g. 10 to 60 percent)" , "(e.g. 60 to 100 percent)", and "In this example, the size of the preloader is 10%, the size of the character is 50% and the size of the 'rest' is 40%."—So i DID say the character was huge and I didn't say it had to be exactly 60%. I'm sorry if you feel like I attacked you in my previous comment, that was not my intention.

    Again, I sincerely appreciate your help.

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    What you want to do is make a preloader to preload the preloader. LOL! Why complicate your life? Just Preload everything at once and play with
    the script i made to you,
    if (percent > 10) { //load this } if (percent >50){ //load this other thing }
    and so on.

    ANother thing is, you can make the preloader in a separate .swf , that will check the character and the preloader size until %40. Then when that finishes loading, you
    can go to frame 2, and there, you can make another preloader, that will load all your game externally from a separate .swf with
    loadMovie("mygame.swf")
    make an empty movieclip, and load your game inside of that, from %40 to %100. Name it "holder" and use
    holder.loadMovie("mygame.swf")
    Good luck
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  19. #19
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Hey Angelhdz,

    I never said I wanted to preload the preloader. All I want is for the character clip to show as soon as that is possible, without having to wait for the character clip to load before displaying the preloader. Arbitrary numbers such as '40%' will not fix my problem.

    Anyway, I'll figure things out. Thank you for trying to help. It makes me genuinely sorry to tell you your code is not helpful, but I didn't ask for a preloader. Just check my original post. I asked how to place a clip onstage without having to load it before the movie shows. Clearly you don't know, which I don't blame you for because neither do I.

    I hope this miscommunication hasn't frustrated you too much, that wasn't my intention.

  20. #20
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Hello fellow geeks,


    I'm working on a little platformer. Building the preloader now, and it's going to look amazing. Just one little problem: I want to use the character movie clip in the preloader.
    You clearly stated "preloader". Then you stated all the process of a preloading:
    1. User somehow opens the .swf.
    2. .swf loads the preloader (white screen) (does not take long)
    3. .swf shows the preloader (preloader is now visible)
    4. .swf loads the character movie clip (preloader still visible)
    5. .swf attaches the character movie clip to the stage (preloader and character clips are now visible)
    6. .swf loads the rest of the game's contents (while preloader and character are still both visible)
    7. if getBytesLoaded() == getBytesTotal() I'll take it form here.
    How you dare to say I misunderstood you?
    Anyway, i'm out! I've really lost my time here!
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

Tags for this Thread

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