A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: showing Loading progress

  1. #1
    Junior Member
    Join Date
    Feb 2004
    Posts
    14

    showing Loading progress

    I want to make a loading animation that shows the percentage of content loaded in a bar (most websites have them).How do you do this?

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    173
    Make a loading bar in flash with width of 100 and make it a movieclip and give it an instance name (preloadBar). Take a Dynamic text field and give it an instance name (input). Don't make it a movieclip. Give a variable name "txtPercent".

    RIghtclick on the movieclip loading bar and paste this action

    onClipEvent (load) {
    Total = _root.getBytesTotal();
    }
    onClipEvent (enterFrame) {
    Loaded = _root.getBytesLoaded();
    Remaining = Total-Loaded;
    Percent = Math.Floor(Number(loaded)/Number(Total)*100);
    _root.preloadBar._xscale = Percent;
    _root.txtPercent = Percent add "%";
    if (Percent == 100) {
    _root.gotoAndPlay(2);
    }
    }


    Place a stop(); on the firstframe.



    Hope it works.



    Kallol

  3. #3
    www.duayne.com
    Join Date
    Oct 2005
    Location
    Philippines
    Posts
    27
    i followed the steps but it wont work... the bar wont load.. and i encountered an error..

    **Error** Scene=Scene 1, layer=preloader, frame=1:Line 1: Clip events are permitted only for movie clip instances
    onClipEvent (load) {

    **Error** Scene=Scene 1, layer=preloader, frame=1:Line 4: Clip events are permitted only for movie clip instances
    onClipEvent (enterFrame) {

    **Error** Scene=Scene 1, layer=preloader, frame=1:Line 7: There is no method with the name 'Floor'.
    Percent = Math.Floor(Number(loaded)/Number(Total)*100);

    Total ActionScript Errors: 3 Reported Errors: 3
    i made sure that the bar i made was a movieclip..

    whats wrong?!

  4. #4
    formally EquanFX
    Join Date
    May 2001
    Posts
    101
    You have to place the code on the movieclip itself not the timeline frame
    and the word "Floor" in Math.Floor should read "Math.floor" i.e. lower-case "f"

  5. #5
    www.duayne.com
    Join Date
    Oct 2005
    Location
    Philippines
    Posts
    27
    i tried doin it again but it wont still work.. yes, there were no errors now..

    i played it, opened the bandwidth profiler, and simulate a 56k modem.. the 100px bar did not move from 1-100, the dynamic txt cant be seen, and it was stuck in the first frame. even if the whole movie was already downloaded, it wont go to frame 2..

    =======

    what i did was:

    Make a loading bar in flash with width of 100 and make it a movieclip and give it an instance name (preloadBar).
    i did understand that perfectly! i made a new layer and followed the instructions..

    Take a Dynamic text field and give it an instance name (input). Don't make it a movieclip. Give a variable name "txtPercent".
    i made a new layer and clicked the TEXT button. i clicked once on the stage, then changed it to dynamic text, name that instance 'input'. i didnt make it a movie clip, i just left it as is.. (did i do something wrong here?) then i gave it a txtPercent var name.

    ====

    what i noticed is that:

    when i simulated a 56k modem, it stuck in the 1st frame, no animation at all! but when i simulated a DSL/Cable modem, it played the movie after it was loaded. BUT, the bar didnt animate and i didnt see the dynamic text..

    could someone tell me whats wrong with this!? thanks! :P

  6. #6
    Senior Member ryantsi's Avatar
    Join Date
    Sep 2005
    Location
    Exeter, Devon
    Posts
    288

    Hey

    The script you have been given works, but i can see one possible problem, the registration point for the Movie Clip has to be the top left hand corner

    This is so it can be scaled from nothing to its full length

    Ryan

  7. #7
    www.duayne.com
    Join Date
    Oct 2005
    Location
    Philippines
    Posts
    27
    I see.. is that so.. hmmm... ill try..

    but am i correct that i didnt convert the dynamic text into any symbol?

    -by the way, thanks again for helping me out in the other thread... i hope i could get it to work after you explain it to me further... :P

  8. #8
    www.duayne.com
    Join Date
    Oct 2005
    Location
    Philippines
    Posts
    27
    did it again.. but it still doesnt work..

    why?

    by the way, this forum, FLASH MX, is this for flash MX (ver6) or flash MX 2004 (ver7)?

    im using MX 2004..

  9. #9
    formally EquanFX
    Join Date
    May 2001
    Posts
    101
    zappakate, and duayne Here is a way to make your preloader work. I'm quite sure a lot of this you already know
    Place a "stop()" on the first frame of the root timeline.
    On frame 1, place something heavy in bytes on the stage to preload, and place a "stop()" on frame 2 of the root timeline.
    Create a movieclip of a bar that is 100 pixels in width (long).
    Make sure the x axis (the far left corner) of the bar is at 0.
    place your new bar movieclip on the stage
    place this code on the movieclip, not the timeline.
    Code:
    onClipEvent (load) {
    	this._width = 0;
    }
    onClipEvent (enterFrame) { 
    	L = _root.getBytesLoaded()/1000;
    	T = _root.getBytesTotal()/1000;
    	P = Math.floor((L/T)*100);
    	this._width = P;
    	_root.txtPercent = P+" %";
    	if (P == 100) {
    		_root.nextFrame();
    	}
    }
    To check the preloader hit "Ctrl Enter" Then hit it again to watch the preloader do it's thing. I hope I didn't leave anything out.
    Good Luck
    A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result

  10. #10
    www.duayne.com
    Join Date
    Oct 2005
    Location
    Philippines
    Posts
    27
    tried your advice... but i didnt work for me..

    im using mx 2004..

    can you tell me whats wrong?

    anyways, thanks for the hep... (im feeling really stupid now)

  11. #11
    Senior Member ryantsi's Avatar
    Join Date
    Sep 2005
    Location
    Exeter, Devon
    Posts
    288

    Hey

    I have made you basic preloader, the fla has 2 scenes, preload and movie, place your content on this scene, or copy the preload bar and the AS on frame one into your movie, and take some time to see how it works

    Ryan
    Attached Files Attached Files

  12. #12
    www.duayne.com
    Join Date
    Oct 2005
    Location
    Philippines
    Posts
    27
    woah!! it definitely worked!!! thanks ryantsi!!! i owe you one...

    but what would i do if i want to have a dynamic text percent loaded?

    i tried making a new layer.. get my TYPE tool. clicked once in the stage (i didnt type anything in it), and made it a dynamic text. then gave it a var name of percent(as indicated in the script u gave me. but i still didnt see the text when i simulated the download..

    how would i do this? thanks

    *i think whats important in actionscripting is that you should know what exactly is going inside the script, right? dont just copy and paste the scripts you get in the net. in my case, i know how the script works, and i understand it. but i just dont know why im not getting it right. and thanks to you, i have the working script now... ill try and learn more AS as i go along my flash lessons.*

    thanks again.. and i hope you would still help me with this last preloader problem.. :P

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