-
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!
-
FK'n_dog
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
-
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.
-
FK'n_dog
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.
-
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.
-
FK'n_dog
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
-
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!
-
FK'n_dog
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=0; i!=len; i++) {
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(swfToPlay, container);
};
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);
};
-
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!
-
FK'n_dog
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.
-
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?
-
FK'n_dog
if you do not need a random movie to load on each visit, yes
-
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?
-
FK'n_dog
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.
-
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?
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|