dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: code help

  1. #1
    Member
    Join Date
    Oct 2004
    Posts
    63

    code help

    Hi,

    I need to load external jpegs into a simple flash slide show. The LoadImages example from Koolexchange (I think I got it there) is almost the answer.

    What I need is for flash to calculate how many jpegs are in the folder and upon reaching the last one, loop back to the first. It needs to be setup so more jpegs can be added to the folder without having to open up the flash and change the total of pics etc.

    The only code find that seemed on the trail was this, but I couldn't implement it to my needs:

    I may not have the syntax exactly correct but what is needed to loop back to the beginning is to count the length of the array (or the number of images), then increment the index “i++” only if “i” is less than the array.length. If the index number is greater than the length, set the index to 0 (or 1).
    Something like this:

    for(var i=1; i<this.length; i++){
    then do all this stuff….
    }
    else }
    i=1;
    {
    attached is my KM7 file for lookin'. Thanks for any help!!!

    -Dan
    Attached Files Attached Files

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    My first thought is to not use a for loop.
    Just track and increment on your own then you can always test when i==whatever then i=0

    As for flash knowing how many jpegs are in the folder you are going to need to use some PHP code, PHP can access the file system and get a list of images. I know Chris has some code on the exchange that does that, I probably do too.

    Basically in PHP there is a directory function that can pass a list of files back to flash then you can do what you want.

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Here's a simple example of reading a directory in PHP

    PHP Code:
    <?php
    $dir    
    '/tmp';
    $files1 scandir($dir);
    print_r($files1);
    ?>
    Also found this online example which should do what you need
    PHP Code:
            $folder opendir("."); // Use 'opendir(".")' if the PHP file is in the same folder as your images. Or set a relative path 'opendir("../path/to/folder")'.
          
    $pic_types = array("jpg""jpeg""gif""png");
          
    $index = array();
          while (
    $file readdir ($folder)) {
               if(
    in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types))
           {
            
    array_push($index,$file);
            }
      
          }
          
    closedir($folder);
          echo 
    $index
    Last edited by blanius; 02-23-2010 at 07:37 AM.

  4. #4
    Member
    Join Date
    Oct 2004
    Posts
    63
    Thanks for the leads, Bret. I did some research because I've never incorporated php with flash and think I understand how people use it to populate text fields, but not how it would be set up for my stated needs...

    If this is the current AS for my flash file:
    Code:
    // create a folder called "Images" for image1.jpg , image2.jpg , etc
    scr._alpha = 0;
    pic = 1;
    input = pic;
    
    _root.onEnterFrame = function() {
    	if (scr._alpha>10 && fadeOut) {
    		scr._alpha -= 10;
    	}
    	if (scr._alpha<10) {
    		scr.loadMovie("Images/image"+pic+".jpg", "_self");
    		fadeOut = false;
    		fadeIn = true;
    	}
    	if (scr._alpha<100 && fadeIn && !fadeOut) {
    		scr._alpha += 10;
    	} else {
    		fadeIn = false;
    	}
    	if (input>3) {
    		input = 3;
    	}
    	if (Key.isDown(Key.ENTER)) {
    		fadeOut = true;
    		pic = input;
    	}
    	
    };
    
    inputField.onKillFocus = function() {
    	input = pic;
    };
    stop();
    And this is the current AS for the "next slide" button:

    Code:
    on(press){
    	if (pic<4 && !fadeIn && !fadeOut) {
    		fadeOut = true;
    		pic++;
    		input = pic;
    	}
    }
    How would I implement your php solution into this scenario? Hope this question isn't a pain in the arse!

    Thanks again!

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