Skip to main content
Inspiring
November 2, 2010
Answered

Very basic XML question

  • November 2, 2010
  • 1 reply
  • 685 views

I'm currently using two arrays to load a sequence of videos in 2 zones of the Flash movie.

var zoneAarray:Array = new Array("movie1.mp4", "movie2.mp4", "movie3.mp4");

var zoneBarray:Array = new Array("movie4.mp4", "movie5.mp4", "movie6.mp4");

var clipA:String = zoneAarray[0];

var clipNumberA:int = 0;

var clipTotalA:int = zoneAarray.length -1;

var clipB:String = zoneBarray[0];

var clipNumberB:int = 0;

var clipTotalB:int = zoneBarray.length -1;

Everything works fine, but I would like to import the list of videos from an XML file instead of hard-coding it in Flash.
TIA, --Eric

This topic has been closed for replies.
Correct answer

Thanks again.

The missing piece was to get the loader set up so I could extract data from it. This is what I ended up with and it's working...

var theMovies:XML = new XML();

var xmlLoader:URLLoader = new URLLoader();

var url:URLRequest = new URLRequest("movielist.xml");

xmlLoader.load(url);

xmlLoader.addEventListener(Event.COMPLETE, onXmlLoad);

function onXmlLoad(e:Event):void

{

theMovies = XML(xmlLoader.data);

var zoneA:XMLList = theMovies.zoneA.movie;

var zoneB:XMLList = theMovies.zoneB.movie;

...
}


Great. Please mark the thread as answered.


1 reply

November 2, 2010

So, what is your question? XML in AS3 is quite easy compared to prior versions... Google AS3 XML for a wealth of info...

But generally, your xml would like something like:

<movies>
    <zoneA>
        <movie>movie1.mp4</movie>
        <movie>movie2.mp4</movie>
        <movie>movie3.mp4</movie>
    </zoneA>
    <zoneB>
        <movie>movie4.mp4</movie>
        <movie>movie5.mp4</movie>
        <movie>movie6.mp4</movie>
    </zoneB>
</movies>

You load it with a URLLoader... once in you could get the list of movies in zoneB with:

var zoneB:XMLList = theMovies.zoneB.movie;

and then each individual movie like:

trace(zoneB[1]);

movie5.mp4

Inspiring
November 2, 2010

Thanks for your response. My frustration is that Adobe's documentation for Flash is poorly written and I have to rely on Google and forums to learn the basics. And we all know how accurate Google results can be.

The XML file is simple. Mine looked almost identical to yours.

My question is how to get the information out of the XML file so I can use it in the script. Basically the movie names and the number of movies in each zone.

Thanks.

November 2, 2010

Really? Flash Help, and Google, work pretty well for me... I agree filtering can be cumbersome though.

>>My question is how to get the information out of the XML file so I can  use it in the script. Basically the movie names and the number of movies  in each zone.

Let's say you assign your loaded xml into the variable theMovies:

var zoneB:XMLList = theMovies.zoneB.movie;

You get an XMLList of movie nodes inside zoneB. Look in the Help re the XMLList object. You can iterate each movie using the list and its length() method:

for(var i:int = 0; i < zoneB.length(); i++){

     trace(zoneB);

}

will trace movie4,5,6... You can stick them in an array, use them as is, etc. You can just trace the list like trace(zoneB); and you will see the xml nodes too:

<movie>movie4.mp4</movie>
<movie>movie5.mp4</movie>

<movie>movie6.mp4</movie>