The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 12 of 12

Thread: Can AS3 or XML "read" files from a directory?

  1. #1

    Can AS3 or XML "read" files from a directory?

    What I want is for flash to grab files from a directory without knowing what files are there. I dont think it's possible with AS3 but I'm not too sure about XML, and if I can get it into a xml file, then i can ccess it from as3.

    The concept might be confusing so an example would be if I had a mp3 player and I wanted to play files from a certain directory but not know what files were in that directory. I would assume XML can "scan" folders for files with a specified exstention and store that information in an array of somesort.

  2. #2
    I'm not sure but you cant access I/O with AS 3.0 unless you use AIR apps.

  3. #3
    XML is not a processing or scripting language, there's no way to generate "dynamic" content solely within an XML file. You would need to use a server-side technology such as PHP or ASP to do something like this on the web, or use the AIR file APIs to do something like this on the desktop.

  4. #4
    Quote Originally Posted by McGuffin View Post
    XML is not a processing or scripting language, there's no way to generate "dynamic" content solely within an XML file. You would need to use a server-side technology such as PHP or ASP to do something like this on the web, or use the AIR file APIs to do something like this on the desktop.
    Cool, exactly what I needed to know. ty.

  5. #5
    Great, best of luck

  6. #6

    any joy?

    Quote Originally Posted by substance View Post
    What I want is for flash to grab files from a directory without knowing what files are there. I dont think it's possible with AS3 but I'm not too sure about XML, and if I can get it into a xml file, then i can ccess it from as3.

    The concept might be confusing so an example would be if I had a mp3 player and I wanted to play files from a certain directory but not know what files were in that directory. I would assume XML can "scan" folders for files with a specified exstention and store that information in an array of somesort.
    Hey there substance,

    Wandered accross your post... had any joy with this using AS3 since these posts? Or did you use a server side language in the end? What you're after is exactly the kind of thing im trying to develop, ie use AS3 to read folder contents and then work out which files it wants..

    Rjl

  7. #7
    Its actually pretty simple. My PHP knowledge is poor, but using an example on this page, heres something quick that should work, it returns all the files in a directory specified (but not subdirectories, but I'm sure you can find an example on the same page if you need that):

    Code:
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    
    var urlLoader:URLLoader = new URLLoader ();
    var urlRequest:URLRequest = new URLRequest ('whatever.php');
    var urlVars:URLVariables = new URLVariables ();
    
    urlVars.folder = 'path/to/folder';
    urlRequest.data = urlVars;
    urlRequest.method = URLRequestMethod.POST;
    
    urlLoader.addEventListener (Event.COMPLETE, onComplete);
    urlLoader.load (urlRequest);
    		
    function onComplete (evt:Event) : void {
    	var xml:XML = XML (urlLoader.data);
    	trace (xml);
    }
    PHP Code:
    <?php
    if ($handle opendir($_POST['folder'])) {
        
    $xmlReturn "<data>";

        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
               
    $xmlReturn .= '<file name="'.$file.'" />';
            }
        }
        
    closedir($handle);
        echo (
    $xmlReturn.'</data>');
    }
    ?>
    Simply paste the actionscript into your timeline, and create a new php file (I chose the name 'whatever.php' but it doesn't matter, as long as you specify it correctly in the actionscript), and paste in the PHP code.

  8. #8
    does it work for you? it doesn't output anything for me...
    Breathe..

  9. #9
    same here

  10. #10
    this gallery tutorial uses php to pull from a directory....tested the source and it works perfectly. Enjoy

    http://active.tutsplus.com/tutorials...pt-30-and-php/

  11. #11
    Ive got no error but it traces absolutely nothing

    EDIT: yes i know this post is old, but maybe someone nowadays knows how to do this?

  12. #12
    I posted a working chunk of PHP in another thread a few minutes ago, so anyone looking for the working file reader go to: http://www.kirupa.com/forum/showthre...m-external-swf

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012