A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: dynamic loading of all images in a folder

  1. #1
    Junior Member
    Join Date
    Oct 2003
    Posts
    3

    dynamic loading of all images in a folder

    ------Flash MX 2004 Pro------
    Is there a simple(?) way to auto- and dynamicaly load all images in a specific folder with, for example, your holliday images. My images names are auto generated by my digital camera and looks like this:

    IMG_0134.JPG
    IMG_0135.JPG
    IMG_0142.JPG
    IMG_0144.JPG

    The best thing would be if some code could load all images in a folder irrespective of the file names (my_image_1a.jpg, myCat.jpg, IMG_0134.jpg, IMG_04.jpg etc.)

    Please help me. I don't want to manualy write a long list, xml or similar

    Thanx


  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    If you have PHP installed on your server you could use that to read the content of the directory and return a list of files to the flash movie.

    I think something like this should work,

    PHP Code:
    <?php
    $dir 
    'path/to/the/directory';
    $numfiles 0;

    if (
    is_dir($dir)) {
        if (
    $openDir opendir($dir)) {
            while (
    false !== ($file readdir($openDir))) {
                if (
    $file != '.' && $file != '..') {
                    if (
    is_file($dir '/' $file)) {
                        
    $f explode('.'$file);
                        
    $ext array_pop($f);
                        if (
    $ext == 'jpg') {
                            echo 
    "&filename$numfiles=$file";
                            ++
    $numfiles;
                        }
                    }
                }
            }
        }
        
    closedir($openDir);
    }

    ?>
    which could be run using the LoadVars object, and would return variables named filename0, filename1 etc...

    Code:
    var lv = new LoadVars();
    lv.onLoad = function(ok) {
        if (ok) {
            var i = 0;
            // loop through the loaded variables
            while (this["filename" + i] != undefined) {
                trace(this["filename" + i]);
                ++i;
            }
        }
    };
    lv.load("your_php_script.php");

  3. #3
    Junior Member
    Join Date
    Oct 2003
    Posts
    3

    Thanx

    Thanx, that works too.
    But the thing I realy wanted was to do this directly from Flash, but I don't think it's possible, after looking around on different forum's. Then your solution must be the best, i guess?!

    /bnet

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    I think the best you can do directly from flash is to check to see if a file exists,

    http://www.flashguru.co.uk/checking_...ile_exists.php

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