A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: preload actionscript using "getBytes" problems

  1. #1
    Member
    Join Date
    Nov 2011
    Posts
    34

    preload actionscript using "getBytes" problems

    Okay, so I'm now trying to use information I've found from hundreds of webpages all talking about how to check to see if your external .swf has loaded yet.

    So, in my first frame I have nothing
    In my second frame, I have this script:

    var mova = loadMovie("QM-SWF-01.swf", "mc1");
    var whatigot = mova.getBytesLoaded();
    var whatineed = mova.getBytesTotal();

    if (whatigot == whatineed) {
    gotoAndPlay("six");
    }

    In my third frame, I have this script:

    gotoAndPlay("two");

    Problem is, I know that my script in frame 2 is not right...but I'm pretty sure I've followed all the advice from all of the webpages...and nothings working.

    What happens is, even if the movie hasn't loaded yet, it jumps ahead to frame 6, as if completely ignoring the "==".

    The only thing I think it could be is if I'm not calling the "getBytesTotal()" and "getBytesLoaded()" properly or something.
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    You have to put the loading code in frame 1 and make frame 2 have no script.
    That way you are doing it now, it keeps returning to the point where it starts loading.

  3. #3
    Member
    Join Date
    Nov 2011
    Posts
    34
    w.brants, that doesn't seem to work either.

    The following code is now on my first frame:


    var mova = loadMovie("QM-SWF-01.swf", "mc1");
    var whatigot = mova.getBytesLoaded();
    var whatineed = mova.getBytesTotal();

    if (whatigot==whatineed) {
    gotoAndPlay("six");
    }


    When I play the movie (I upload to my server each time, and delete all of my cache), it always skips to the sixth frame, regardless of the amount of the loaded external .swf.

    If I change the code to read:


    var mova = loadMovie("QM-SWF-01.swf", "mc1");
    var uno=1;
    var dos=2;

    if (uno>=dos) {
    gotoAndPlay("six");
    }


    then the animation correctly goes to the second then the third frame, and then loops (since 1 is never greater than or equal to 2).

    That is why I still think I'm doing something wrong with the "getBytesLoaded()" portion of the code. I'm not a professional coder, and I always find this sort of thing difficult to understand...

    For instance, do I correctly do the var for the loadMovie, and then use the variable name in the getBytesLoaded()?

    Or should I use the "mc1" for the "getBytesLoaded()"?

    Or should I put something in those brackets - getBytesLoaded(mc1) - ?

  4. #4
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Maybe you could look at the code from the preloader Remus created.
    There's one on his website in the KoolMoves / AS1 section
    http://necromanthus.com/main.html

  5. #5
    Member
    Join Date
    Nov 2011
    Posts
    34
    Thanks, I saw that.

    the difference there is that it looks like the getBytesLoaded() is referring to the main movie file, so there's no "this.getBytesLoaded()", or "externalswf.getBytesLoaded()", so I still don't understand how I'M supposed to write out my example...

    I feel like this is such a common issue, I don't know why I cannot find the answer.

  6. #6
    Member
    Join Date
    Nov 2011
    Posts
    34
    Okay, this is my solution that works (so far)!:

    Setup:
    - I have a Koolmoves file that consists of seven (7) frames.
    - I have renamed all of the frames so that the first frame is called "one", the second frame is called "two", etc.
    - In frame 6, I created an empty movieclip using Koolmoves tools, and in that movie clip I imported a .swf that I created previously...it's an external .swf.
    - I copied and pasted that movieclip into the first frame, and then scaled it down as small as I could; then I copied it again to the second and third frames (I'm not sure if I needed to do this, but at this point, I don't care...if it works it works).
    - You'll notice that in this example I'll have a few frames in the middle that never get used...those were for my own internal testing.
    - Next, I created a few actionscripts using AS 1

    (I'm using AS 1 because I heard that in AS 3 there is no "getBytesLoaded()" commands, and I've looked at the examples for the new way to do that, and they look more complicated...and I've got to get this project out the door ASAP!)

    Frame 1:

    //mc1 is the name that Koolmoves gave the empty movie clip...I chose to keep that. //QM-SWF-01.swf is the external .swf I created previously
    //which is in the same directory as my final .swf file.

    mc1.loadMovie("QM-SWF-01.swf");


    Frame 2:

    var whatigot=mc1.getBytesLoaded();
    var whatineed=mc1.getBytesTotal();

    if (whatigot>=whatineed) {
    gotoAndPlay("six");
    }


    Frame 3:

    gotoAndPlay("two");

    Frames 4 - 5 never get used, unless my scripts didn't work, in which case I would have seen my frames run through, which was how I could tell what was working or not working.

    Frame 6:

    stop();

    A big thank you to w. brants and Bob Hartzell for all of your patience. I'm hoping this was all the help I'll need for this project.

  7. #7
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Glad that you got it to work.
    When using AS3, you use the Loader class to load a swf.
    It has a property contentLoaderInfo that refers to an object containing information about load progress.

  8. #8
    Member
    Join Date
    Nov 2011
    Posts
    34
    Well damn.
    I spoke too soon. Evidently, my way doesn't work when you're trying to preload multiple external .swf files.

    This is freaking making me want to never use flash in any way ever again.


    I only have two options left: AS3 using the Loader class, which I think would require a boat load of research.

    If anyone has a link to a good reference for Loader classes that would be very much appreciated.


    The other thing I'm thinking about doing is to write out one long "while" loop on the first frame do all of my "loadMovie"s.

    So, in the first frame, I'd load all my movies doing:
    emptymovieclip1.loadMovie(movie1.swf);
    emptymovieclip12.loadMovie(movie2.swf);
    etc.;


    then below all of the loadMovie's, I would have:

    n=0
    a=0
    b=0
    (then c-o =0)

    while (n!=15){
    if a!=1{
    if getBytesTotal==getBytesLoaded{
    n=n+1
    a=1
    }
    }
    if b!=1{
    if getBytesTotal==getBytesLoaded{
    n=n+1
    b=1
    }
    }
    etc
    }


    If anyone has any more references for loading multiple external .swfs into one main koolmovie movie file, that would be much appreciated...I don't know why mine didn't end up working. If anyone thinks this is fun and wants to check it out, here's the fun file:

    http://www.brianheagney.com/Q-Matic/...-HC_Fin_30.fun

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    For documentation on classes, the AS3 language reference is a good place
    http://help.adobe.com/en_US/FlashPla...ay/Loader.html

    KoolMoves itself has a class named AssetManager
    http://koolexchange.com/docs/km/km/c...etManager.html
    It doesn't support loading swf but you could load all your swf files as binary and load from a binary when you need it. There is a little delay loading a movie from a bytearray but not much.
    For this approach, you would use getAsset from the AssetManager to get your preloaded bytearray and use the loadBytes method from a Loader object to load it from there.
    Last edited by w.brants; 03-19-2012 at 02:51 AM.

  10. #10
    Member
    Join Date
    Nov 2011
    Posts
    34
    w. brants, thanks again for pointing me to the above pages. Howeve, I spent a couple hours trying to figure all that stuff out...and the problem is, I just don't understand it yet, and I need to move forward.

    So, I'm going to post one more time, and hopefully illuminate this a little more:

    Here's my code (numbers are the frame names that I use in the .fun):

    one
    mc1.loadMovie("QM-SWF-01.swf");

    two
    if (mc1.getBytesLoaded>=mc1.getBytesTotal){
    gotoAndPlay("five");
    }

    three
    gotoAndPlay("two");

    four
    //i leave this blank so I can visually see where my different movie clips are

    five
    mc2.loadMovie("QM-SWF-02a.swf");

    six
    if (mc2.getBytesLoaded>=mc2.getBytesTotal){
    gotoAndPlay("nine");
    }

    seven
    gotoAndPlay("six");

    eight
    //blank

    nine
    mc3.loadMovie("QM-SWF-02b.swf");

    ten
    if (mc3.getBytesLoaded>=mc3.getBytesTotal){
    gotoAndPlay("thirteen");
    }

    eleven
    gotoAndPlay("ten");

    twelve
    //blank

    thirteen
    //for a debugger, I had a congratulatory message here...but that's only the first success

    fourteen
    //if you get here and you have to wait for a video to load...then there's something wrong with my preloader. However, if the movie plays right away, that's what I want

    Also, when you push the button, the video should also play right away, no loading! If it has to load, then something is wrong.

    fifteen and sixteen are also video files.

    So, before I get into the more complicated AssetManagers or the other AS3 stuff, I should be able to write this correctly...or rather, I figure that if I can't get this simple loadMovie stuff correct, there's no way I'll be able to get the other stuff that you recommend, w.

    Here's a link to the .fun file:
    http://www.brianheagney.com/Q-Matic/...PL-test_05.fun
    Here's a link to the external .swf:
    http://www.brianheagney.com/Q-Matic/...load-files.zip

    Also, I would be hiring or sub-contracting someone else to do this, but it seems that no one else in my network knows flash. So I'm getting kind of desperate. I would imagine that this would only take a half-hour for someone knowledgeable in Koolmoves.

    Is there anything else I'm missing?

    thanks again to anyone who can help out.

  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I thought you were doing a Kiosk? if the files are local you don't need to jump through all these hoops.

    The loader thing had me a bit confused first time I tried to use it. For a Kiosk I did that need to load from a server I used a class like http://www.greensock.com/loadermax/

  12. #12
    Member
    Join Date
    Nov 2011
    Posts
    34
    Actually, I'm not doing the kiosk itself, I'm doing a flash presentation so that users can view an online demo of how the kiosk systems are integrated into waiting-rooms etc...so, it's a series of animations, and it's going to be available online for potential clients to see, so I don't want any buffering within the actual animation.

    And oh, I know about the local vs. non-local thing, I completely wish this was a local thing.

    I'll check out the greensock stuff...it seems like it should work, but we'll see if my noobie/hack mind can get around all the details...

    But really, all I want to do is have a .swf that preloads external .swfs, so that other online users don't have to experience buffer time while going through the animation...thanks again.

  13. #13
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by brianheagney View Post
    But really, all I want to do is have a .swf that preloads external .swfs, so that other online users don't have to experience buffer time while going through the animation...thanks again.
    In the end users will have to wait one way or another if they have a slow connection, many these days are over 20mps and so it's not as big an issue.

  14. #14
    Member
    Join Date
    Nov 2011
    Posts
    34
    I think I've got something, but after reviewing the Koolmoves AS3 documentation, I'm at a loss trying to find anything about the Loader() class. I started to look for AltLoader() and noticed that while it says I can load a .swf as a bytearray, I have no idea how to Load it as a byte array...

    But, more importantly, the AS3 documentation notes that you should use the AltLoader() for loading content not supported by the "Loader Class".

    However, I can't find documentation about the Loader class itself, so I don't how to properly handle it.

    In any case, here is the code that I'm writing, that I think would work for what I want it to do:

    var ldra=new Loader();
    mc1.ldra.load(new URLRequest("QM-SWF-01.swf"));
    mc1.ldra.addEventListener(Event.COMPLETE, goon)
    var loadtester=1;

    function goon(e:Event){
    loadtester=5;
    }

    while (loadtester=1){
    }

    if (loadtester==5){
    gotoAndPlay("thirteen");
    }
    Basically, this one page loads the .swf (QM-SWF-01.swf) into the empty movieclip (mc1).
    Then, I add a listener that waits for the load to complete, then executes the "goon" function, which makes the variable "loadtester" equal 5.

    The while loop will run until the .swf loads completely,
    then, the "If" statement will run, skipping ahead to frame thirteen...I know I didn't need the if statement, but I'm setting up the architecture for a later addition, when I get this to work.

    So far, I know it's looping properly in the while loop at least, I just need to know how to use the Loader class.

    I'm using AS3 now, by the way, screwing the whole "getBytesTotal" crap that never worked (or, that I could never get to work).

  15. #15
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    A Loader object can load swf movies. AltLoader was developed to load text files.
    An instance if the Loader class is a visual object that should be added to the display list.
    So what you should do instead is

    code:
    var ldra:Loader = new Loader();
    addChild(ldra);
    ldra.load(new URLRequest("QM-SWF-01.swf"));



    or if you want it to be a child of mc1

    code:
    var ldra:Loader = new Loader();
    mc1.addChild(ldra);
    ldra.load(new URLRequest("QM-SWF-01.swf"));


  16. #16
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Using the AssetManager, you can do it like this.

    frame1 :
    Code:
    // import the required classes
    import km.core.*;
    
    // add a loader object to the stage
    var myLoader:Loader = new Loader();
    addChild(myLoader);
    
    // initiate the load
    AssetManager.loadBinaries('swf1.swf','swf2.swf');
    frame2 : empty frame with label 'loopFrame'

    frame3 :
    Code:
    if (AssetManager.getQueueLength() > 0) gotoAndPlay('loopFrame');
    frame4 :
    Code:
    myLoader.loadBytes(AssetManager.getAsset('swf1.swf', false));
    
    stop();
    frame4 is the start of your normal movie.
    I put a stop action there since this test code contains no further frames. Otherwise you shouldn't put that there of course.
    The other line of code loads the swf from a byte array. It's a bit like loading it externally but a lot faster.
    The loader object can be reused so in another frame you can use a different line of code to load new content into the same loader object.
    Like mentioned in my previous post, you can also choose to add the loader object to mc1 instead of to the stage directly.

    If you wish, you can add a dynamic textfield to frame2 and frame3 and add a line of code to frame2 to set the text to the name of the item that is currently being loaded.
    AssetManager.getQueueCurrent();
    returns a string with the name of that item.
    Last edited by w.brants; 03-21-2012 at 02:51 AM.

  17. #17
    Member
    Join Date
    Nov 2011
    Posts
    34
    Holy Moly!!!!! I think it freaking works!!!

    This was exactly what I was looking for the whole time!!!

    I can't begin to tell you how excited I am.

    I may have to write up a tutorial, or a page or something that goes over the problem, the solution, and the code, and thank you all for it.

    I mean, I don't want to jump the gun, but I just did a test with three out of the 15 animations, I cleared my internet cache, refreshed, and the animation looped until all was loaded, and I went quickly through the animation to ensure that they were all completely loaded and they in fact were!!!!

    So so happy to have this one more or less understood.

    Oh, and I actually rewrote the code a little...I'll write more, but here's the first frame of my code:

    // import the required classes
    import km.core.*;

    // add a loader object to the stage
    // I am adding three distinct loader objects, because I have three distinct external .swfs
    //when I didn't have three distinct loader objects, I couldn't figure out how to play
    //the each individual .swf in the same empty movie clip...
    //I'm probably wasting resources somehow, but it works for me so far...

    var myLoadera:Loader = new Loader();
    mc1.addChild(myLoadera);

    var myLoaderba:Loader = new Loader();
    mc2.addChild(myLoaderba);

    var myLoaderbb:Loader = new Loader();
    mc3.addChild(myLoaderbb);

    // initiate the load
    AssetManager.loadBinaries('QM-SWF-01.swf','QM-SWF-02a.swf', 'QM-SWF-03a.swf');
    AssetManager.messenger.addEventListener('complete' , loadComplete);

    function loadComplete(e:Event){
    gotoAndPlay("start");
    }

    stop();
    Then, on the frame labeled "start", I have:

    myLoadera.loadBytes(AssetManager.getAsset('QM-SWF-01.swf', false));
    and a button that advances one frame, where I'll have:

    myLoaderba.loadBytes(AssetManager.getAsset('QM-SWF-02a.swf', false));
    etc.

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