A Flash Developer Resource Site

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

Thread: is it possible to examine on jpg loading ?

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    103
    Hi all

    is there anyway to Examine on pictures of jpg type

    when loading if so which script

    I should use ?

    is it something like

    i = "mypic.jpg";

    if(i.getBytesLoaded() == i.getBytesTotal()){

    myClip.loadMovie(i);

    }else {

    display = "please wait picture is loading";

    }

    please help soon


  2. #2
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    you want a preloader for you picture?
    if your picture is externally loaded to a movieclip, just preload the clip;
    "mc" is the instance name of the clip the pic is loaded to.
    this code goes on the timeline, frame 1

    mc.loadMovie("your_image.jpg");


    this code goes directly on the movieclip;

    onClipEvent (load) {
    this._alpha = 0;
    }
    onClipEvent (enterFrame) {
    L = this.getBytesLoaded() / 1024;
    T = this.getBytesTotal() / 1024;
    P = L / T * 100;
    if (P == 100) {
    this._alpha = 100;
    }
    }

    If you need further assistance, just ask.


  3. #3
    Senior Member
    Join Date
    Aug 2002
    Posts
    191
    nice code EQFlash. Even i would have said the same thing.
    but we should avoid using events like "onClipEvent (enterFrame)" for it keeps playing even when task has been achived.

  4. #4
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    You're right Sid

  5. #5
    Flash MX code:

    movieclip.prototype.load = function(obj,img,posx,posy) {
    obj.loadMovie(img);
    obj._x = posx;
    obj._y = posy;
    loaded = obj.getBytesLoaded();
    total = obj.getBytesTotal();
    }

    call it like this:

    load(placeholder_MC, "picture.jpg", 100,100);

    That«s it...
    just take out the values from loaded and total to show the loading-progress...

    have fun,

    Manuel

  6. #6
    Senior Member
    Join Date
    Aug 2002
    Posts
    191
    Trooper, your code looks very professional man.

  7. #7
    Member
    Join Date
    May 2001
    Posts
    42
    troopers code is exactly what i have been searching for and it works perfectly.

    I have one question though, i am having trouble grabbing the variable from loaded...this is the code i inserted into the main chunk of code...


    info.text = loaded + "% completed";

    where text is my dynamic text box

    can anyone help me with the load progress?

  8. #8
    Senior Member
    Join Date
    Aug 2002
    Posts
    191
    try this one BOC,

    info.text = movieclip.loaded + "% completed";

  9. #9
    Member
    Join Date
    May 2001
    Posts
    42
    thanks for the help Sid, that line makes more sense but im still messing something up.

    this is the code in my first frame:

    movieclip.prototype.load = function(obj,img,posx,posy) {
    obj.loadMovie(img);
    obj._x = posx;
    obj._y = posy;
    loaded = obj.getBytesLoaded();
    total = obj.getBytesTotal();
    info.text = loadtext.loaded + "% complete";
    }
    load(dropzone, "pic.jpg", 100,100);

    the image still appears in dropzone, but when i test it on a low bandwidth connection, i dont get a load sequence. so i dont think it works right.

    i put my dynamic text box, instance name 'text', in a movie clip instance named 'loadtext'. that movie is 100 frames long. i know im missing something...

  10. #10
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    Originally posted by Trooper977
    Flash MX code:

    movieclip.prototype.load = function(obj,img,posx,posy) {
    obj.loadMovie(img);
    obj._x = posx;
    obj._y = posy;
    loaded = obj.getBytesLoaded();
    total = obj.getBytesTotal();
    }

    call it like this:

    load(placeholder_MC, "picture.jpg", 100,100);

    That«s it...
    just take out the values from loaded and total to show the loading-progress...

    have fun,

    Manuel

    Does that mess with the loading of ANY MC or just the movieclip in question? I mean, I sould use the MovieClip.prototype.load = ... and then I can use to any instance or I use myMC.prototype.load? I guess it`s the earlier, but I am never sure

    Thanks,
    Leo

  11. #11
    Member
    Join Date
    May 2001
    Posts
    42
    it doesnt work when i replace movieclip with dropzone (which is the name of the movie clip i am loading my .jpgs into) so i guess thats the answer.


  12. #12
    Hi,

    movieclip.prototype.functionname = function (.....)
    is a standard code.
    movieclip.prototype is a once set multiusuable code.

    Don«t change movieclip into some other clipname or so.
    just use:

    yourmovie.load (......);

    That«s all.
    Hope your pic-loading works well!

    Manuel

  13. #13
    absent
    Join Date
    Aug 2000
    Location
    NB, Canada
    Posts
    155

    i dono....

    i'm sorry guys but i can't seem to get this to work... the
    code looks great, and the image loads fine but i can't get
    the proper file size of the image being loaded... is there
    something i'm doing wrong?... (i've been fighting with
    this sort of code for a week now)

    __________________________________________________ ______
    movieclip.prototype.load = function(obj,img,posx,posy) {
    obj.loadMovie(img);
    obj._x = posx;
    obj._y = posy;
    loaded = obj.getBytesLoaded();
    total = obj.getBytesTotal();
    percloaded = total / 1024;
    }
    __________________________________________________ ______

    i have this attached to a button:

    __________________________________________________ ______
    on (release) {
    load(Loader_MC, "1.jpg", 0,0);
    }
    __________________________________________________ ______


    it's the same since i've started trying when i hit the
    button my dynamic text field gives me "0.00390625" then if
    i hit it again it removes the image and gives
    me "22.2998046875"

    i'm at a loss here.. any ideas?!..

    thanks a bunch!.. ^_^ !!

  14. #14
    Your code:
    Code:
    percloaded = total / 1024;
    change it to
    Code:
    percloaded = loaded / total;
    PROBLEM IS THIS:
    When you load a jpg into a "holder" instance that you created (ie not created at runtime), you have a obj.getBytesLoaded() and obj.getBytesTotal() of 4 bytes!!
    Note: THIS WON'T HAPPEN IF YOU ARE LOADING FROM DISK because it loads instantly, but if you put it on the net, you are going to have problems.

    This explains why your text field initially returned 0.00390625 (4 bytes/1024).
    The second time you update the text field, it returned 22.2998046875 (22835 bytes/1024). The size of you jpg is actually 22835 bytes, not 4 bytes. Because you asked the obj the loaded and total bytes almost instantly after your loadMovie command, the initial return of both getBytesLoaded() and getBytesTotal() will be 4 bytes.
    weird...?

    SOLUTION:
    Make your placeholder at runtime:
    Code:
     
    //create the empty clip:
    this.createEmptyMovieClip("holder",1);
    //load a picture, (the random(999) is to prevent it from caching, just so you can test it more than once)
    holder.loadMovie("http://yourdomain.com/pic.jpg?" + random(999));
    
    //this traces the bytes loaded and total:
    this.onEnterFrame=function(){
    	trace(this.holder.getBytesLoaded());
    	trace(this.holder.getBytesTotal());
    }


    If you don't believe me, try this:
    Code:
     
    //make your own "holder"
    //load a picture to "holder", (the random(999) is to prevent it from caching, just so you can test it more than once)
    holder.loadMovie("http://yourdomain.com/pic.jpg?" + random(999));
    
    //this traces the bytes loaded and total:
    this.onEnterFrame=function(){
    	trace(this.holder.getBytesLoaded());
    	trace(this.holder.getBytesTotal());
    }
    The first two values that you see in the output window is:
    4
    4
    (even when the picture doesn't exist, try http://yahoo.com/sdfasfasd.jpg)

    Hope I didn't confuse you
    [Edited by McFalski on 08-15-2002 at 10:21 AM]

  15. #15
    Hi there,

    it is as McFalski says.
    just one thing to add:

    To recieve the percentage of loading-progress u must use:
    percent = loaded*100/total;

    Gives you a number from 0 up to 100.

    Just use: yourmovieclip.output.text=percent+" %";

    That«s it.

    Manuel

  16. #16
    absent
    Join Date
    Aug 2000
    Location
    NB, Canada
    Posts
    155

    thanks!

    thank you very much that helped with loading the image
    however i have a bunch i want to load and it doesn't
    continue to work after i load the first one...
    http://www.smythe.nbcc.nb.ca/class99...misc/test2.fla
    this is my test file.. it's ugly but should be working
    just fine... if you'd be so kind as to take a look..
    thanks a lot.. this one has really got me stumped!

    @_*;;;


  17. #17
    Member
    Join Date
    May 2001
    Posts
    42
    ok now im totally and completely lost.
    can i get a definitive answer to how to preload a .jpg?
    i am new to actionscript and im running around in circles at everyones different oppinion as to how to do this.

    all i want to do is to preload a .jpg and show the bytes loading progressively in a dynamic text box. i can get the .jpg to load, but i cant get my dynamic text box to show the bytes loading.

    is there just a canned answer to this?

    explain it to me as if i were a 2 year old ; D

  18. #18
    Member
    Join Date
    Apr 2002
    Posts
    97
    Originally posted by bucket of chicken
    ok now im totally and completely lost.
    can i get a definitive answer to how to preload a .jpg?
    i am new to actionscript and im running around in circles at everyones different oppinion as to how to do this.

    all i want to do is to preload a .jpg and show the bytes loading progressively in a dynamic text box. i can get the .jpg to load, but i cant get my dynamic text box to show the bytes loading.

    is there just a canned answer to this?

    explain it to me as if i were a 2 year old ; D
    Take a look at this site. Go to the pictures page and see if it is something like what you want with the preloader.

    http://www.caprockoutfitters.com/flash/CAP.html


  19. #19

  20. #20
    Another really simple way of making a preloader is to check the width or height of the loaded image. (no bytesLoaded or bytesTotal involved)
    The placeHolder.width will be > 0 only after the image is loaded. Simple way to avoid all that byte stuff.

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