A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: analyzing external files? ie: counting and loading sequentially

  1. #1
    Member
    Join Date
    Jan 2004
    Posts
    33

    analyzing external files? ie: counting and loading sequentially

    I'm building your basic portfolio/gallery site but trying to do everything dynamically.

    What I've got is a menu that loads dynamic jpgs into a MC, depening on the button clicked it finds the right file from the right folder. Thats great for the first image of a series but I would like to have a "next" button that just finds the next jpg in that particular folder and loads it. Ideally when it has run through them all it will loop to the first jpg... but one thing at a time I guess.

    I've got folders like "2003.01", "2003.02", "2003.03", etc and within each of those I've got jpgs named 01.jpg, 02.jpg, etc. If each folder had the same number of jpgs this would be much easier I think but thats not possible.

    How can I load the next jpg dynamically using actionscript?

    Thanks for your time,
    Gabe

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Flash has to know how may images there are in a folder to be able to change change folders. Then the folder names would be put in an array that Flash picks from.

    A next button could look like this.... ( the zero before the number complicates things, this example is for a non zero at the beginning ).

    //Next image load
    on(release){
    i++;
    containerMC.loadMovie("2003.01/"+i+".jpg");
    }

    //Previousimage load
    on(release){
    i--;
    containerMC.loadMovie("2003.01/"+i+".jpg");
    }


    And have ....

    i=0;


    .... in the first frame of the movie.

    Then all the other buttons has to update the i variable so the next buttons know the number of the last loaded image.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Member
    Join Date
    Jan 2004
    Posts
    33
    righty-O, thanks for your reply,

    thats the stuff I'm looking for, and I think I can get that working ok, but any ideas on being able to count the # of jpgs in a folder to set a variable so it only advances if i <= #ofjpgs.

    I don't know if flash has this capability but it seems there would be some way with a little bit of improvisation...

    Let me know if you've got any ideas

    Thanks again,

    Gabe

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Flash can not check folders by itself. But with a serverside script checking the results can be sent in to Flash. Depending on what your server supports you can use php,asp or cgi.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    Member
    Join Date
    Jan 2004
    Posts
    33
    I'm not gunna go there, too much for me to learn right now.

    How about if the script checks to see if a jpg loaded and if not, starts over at 1.jpg? This asumes that the jpgs dont fail to load for someother reason.

    That is rather ghetto but might work, no?

    -Gabe

  6. #6
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173
    I think that will work. Try to load 17.jpg, then do something like


    if (typeof _root["17.jpg"] == "undefined") {
    //load 01.jpg instead
    }

    To put the leading zero on, you'll need to convert the number to a string, and if the length of the string is less than 2, prepend a string "0" to it.

  7. #7
    Member
    Join Date
    Jan 2004
    Posts
    33
    Ok, i got a bit ahead of myself there...

    I'm having problems with adding the i variable, I've got this on the next button:
    code:
    //Next image load
    on (release) {
    i++;
    _root.pictMC.jpgMC.loadMovie(_root.slink11);
    }


    Then I have i=1 on the first frame along with the slink value:
    code:
    slink11 = "portjpgs/2003.01/"+i+".jpg";



    but instead of adding 1 to i, i remains 1 and keeps loading "1.jpg" rather than "2.jpg"

    This is a dumb mistake, I think, how do I prevent i from being turned back to 1?

    What did I do wrong?

    -Gabe

  8. #8
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    The button should have ....

    _root.i++;

    If the timeline stays still on frame one, it wil work. If it returns to frame one, the variable i will be reset.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  9. #9
    Member
    Join Date
    Jan 2004
    Posts
    33
    yup, I gathered that much, but I'm working all on one frame, how can I stop "i" from being reset? It doesn't seem like it should...

    Thanks,

    Gabe

  10. #10
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    I shouldnt. Put a trace on the i on the button and see what happens in the output window.

    Add to the button code, and press repetedly.

    trace(_root.i);


    Or test with...

    on (release) {
    i++;
    _root.pictMC.jpgMC.loadMovie("portjpgs/2003.01/"+i+".jpg");
    }


    Also its good practice not to name anything in Flash, starting with a number.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  11. #11
    Member
    Join Date
    Jan 2004
    Posts
    33
    Sorry to drag this out like this, but I been wrestling with the damn thing for too long now. I've made up a little example fla, so if any of ya'll would give it a look, it would be greatly appreciated.

    Thanks,

    Gabe
    Attached Files Attached Files

  12. #12
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    The variable is called slink11 and not slink ( on the button ). You also have to refer the the main timeline where slink11 resides.. like this....

    _root.pictMC.jpgMC.loadMovie(_root.slink11);

    Then it worked here.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  13. #13
    Member
    Join Date
    Jan 2004
    Posts
    33
    Thanks again for the reply,

    I realized too late that I forgot the slink11 and I also thought I tried the _root.slink11 but I will give it all another shot when I get back on sunday.

    Have a good weekend,

    Gabe

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