#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    660
    Rep Power
    31

    Retrieving xml data and matching extension to execute a particular function?


    I have an XML file that has location pathways of files to load. eg.
    <sample>
    <file>audio/sample.mp3</file> or
    </sample>
    <sample>
    <file>slideshow1.swf</file>
    </sample>

    In my movie, if you click a button, it will load file [0] or [1] using the XML file to provide the pathway. I am trying to create a script that will look at the extension .mp3 or .swf and depending on the extension, will execute a certain function.

    How do I make my movie only look at the last 3 letters of the file text in the XML file??

    Thanks
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,675
    Rep Power
    3164
    You can use substr on the "file" XML node and check what it returns, in this case the last 4 characters:
    Code:
    var test_filenames:Vector.<String> = new <String>["dog.exe", "cat.exe", "elephant.php", "bird.gif"];
    
    // .exe
    trace(test_filenames[0].substr(-4));
    
    // .php
    trace(test_filenames[2].substr(-4));
    
    // Execultable
    switch (test_filenames[1].substr(-4))
       {
          case ".exe" :
             trace("Execultable");
             break;
          case ".php" :
             trace("PHP file");
             break;
          case ".gif" :
             trace("Image file");
             break;
       }
    Quis custodiet ipsos custodes?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    660
    Rep Power
    31
    Hi Tann, great to read from you!

    Thanks for your always helpful replies : )
    Originally Posted by Tann San
    You can use substr on the "file" XML node and check what it returns, in this case the last 4 characters:
    Code:
    var test_filenames:Vector.<String> = new <String>["dog.exe", "cat.exe", "elephant.php", "bird.gif"];
    
    // .exe
    trace(test_filenames[0].substr(-4));
    
    // .php
    trace(test_filenames[2].substr(-4));
    
    // Execultable
    switch (test_filenames[1].substr(-4))
       {
          case ".exe" :
             trace("Execultable");
             break;
          case ".php" :
             trace("PHP file");
             break;
          case ".gif" :
             trace("Image file");
             break;
       }

IMN logo majestic logo threadwatch logo seochat tools logo