A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Using XML to create an SWF playlist?

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Posts
    13

    Using XML to create an SWF playlist?

    Apologies if this has already been asked, but I've done a cursory forum search, and since I'm relatively new to XML, I've not found anything that addresses what I need to do, which is:

    There will be a "pool" of SWF files- I would like to create a "shell" swf that will load an external XML file that will determine which of the files in the "pool" the shell will play.

    Forgive me if my terminology is rather primitive- again, I'm new to XML (I'm an animator by trade.)

    Any help/links would be greatly appreciated!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you will need a server side script to both detect the number
    of swf files in your online folder and write the results to an xml file.

    i use php in this example -

    http://www.jackleaman.co.uk/test/xml...hp_to_xml.html

  3. #3
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Thanks, but:

    We already have someone who can create the XML dynamically- that's no problem. What I need to know is how to create a flash shell that will reference the XML, and figure out which SWFs from the "pool" to play, as listed by said XML.

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    load the xml file into your shell.
    parse the nodes and add the contents to an array.
    if you are loading a random file, shuffle the array,
    and remove the last element from the array as the file to load.
    use the MovieClipLoader class to load the file, and its onLoad
    function to alter any of the properties of the loaded file.

  5. #5
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Oh, my...

    I appreciate the quick response, but I must admit that I have no idea of how to do any of that. I know only the most elementary actionscript, and have never worked with flash/XML interaction, before.

    I was sincerely hoping that there would be a good tutorial or somesuch on how to do what I described.

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    to be more specific in any answer i could give, i would need
    to know which version of Flash that you are using and which
    version of ActionScript you are publishing with (AS2 or AS3)

    you also need to post a sample of the xml file that is dynamically created

  7. #7
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Okay- we're stuck using flash 8 (as the client's computers are rather behind the times, and you can never be too sure.) AS2 is fine.

    As far as the XML goes, we have none, as we have no idea as to how to set something like this up. However, if you have any suggestions as to XML sturcture, we can have our web developer create an online XML generator that conforms to your example.

    Thanks again for your assistance!

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    for simplicity, output the xml file as -
    PHP Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
        <root>
    <node swf='1.swf' />
    <node swf='2.swf' />
    <node swf='3.swf' />
    <node swf='4.swf' />
    <node swf='5.swf' />
        </root>
    load, parse, shuffle etc.. with -
    PHP Code:
    swfArray = new Array();

    /* load the xml file into your shell */
    var _xml = new XML();
    _xml.ignoreWhite true;
    _xml.load("test.xml");

    /* parse and add the contents to an array */
    _xml.onLoad = function(){
    var 
    cNodes this.firstChild.childNodes;
    var 
    len cNodes.length
    for (var i=0i!=leni++) {
    swfArray[i] = cNodes[i].attributes.swf;
    }
    /* loading a random file? shuffle the array */
    trace("Before shuffling - "+swfArray);
    swfArray.sort(function(){return Math.floor(Math.random()*3)-1});
    trace("After shuffling - "+swfArray);
    /* remove the last element from the array  */
    swfToPlay swfArray.pop();
    /* use the MovieClipLoader class to load the file */
    mcLoader.loadClip(swfToPlaycontainer);
    };

    var 
    container:MovieClip createEmptyMovieClip("container"getNextHighestDepth());
    var 
    mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(this);

    /* alter any of the properties of the loaded file here */
    function onLoadInit(mc:MovieClip) {
    trace(swfToPlay+" loaded to "mc);
    }; 

  9. #9
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Hmn, I save the first field as "test.xml", and the second field goes.... where? Is it applied as actionscript to a keyframe, a blank movie on stage?

    Thanks for your help!

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    open a new fla in the same folder as the test.xml and swf files.

    copy/paste the above code into the Actions Panel, frame#1 of the main timeline.

  11. #11
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Fantastic!

    Now- to remove the shuffling of the swfs, I just remove the following:

    /* loading a random file? shuffle the array */
    trace("Before shuffling - "+swfArray);
    swfArray.sort(function(){return Math.floor(Math.random()*3)-1});
    trace("After shuffling - "+swfArray);
    right?

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    if you do not need a random movie to load on each visit, yes

  13. #13
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Urg. When I removed that script, the shell SWF just played the last item in the XML list, over and over. Any reason why this would be happening?

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    that would be the expected result on removing that particular section of script.

    what the script does there is pull a random swf file out of the list of swf
    files that it loads from the xml file.

    without the script, you will always load the last swf file loaded into the xml file.

  15. #15
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    Thanks- what I'm trying to do is to get the "shell" swf to play all of the external SWFs in sequential order (the order they are listed in the XML.)

    Is there a script that would allow this?

  16. #16
    Junior Member
    Join Date
    Feb 2007
    Posts
    13
    I'm looking to somehow alter the above script, so that the "shell" swf plays the external SWFs in the order that they are listed in the XML.

    Any help would be greatly appreciated.

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