Link to home
Start Free TrialLog in
Avatar of petersego
petersego

asked on

How do I load random xml-file

I want my flashmovie to act in different ways, depending on the name of a xml-file.
Which means that if a xml-file does not exist, nothing will happen, but if xmlfile5.xml exist the swf will behave in another way, than if the file existing is named xmlfile7.xml.
But how do I tell in as3 the swf to accept all filenames in the range xmlfile1 to xmlfile10.
Off course only one at a time - and always the lowest - or highest - number.
Something like the attached snippet??
var xmlname="xmlfile"+xmlnumbers;
myXML = new XML();
XML_URL = xmlname+".xml";
myXMLURL = new URLRequest(XML_URL);
myxmlLoader = new URLLoader(myXMLURL);
myxmlLoader.addEventListener("complete", myxmlLoaded);
myxmlLoader.addEventListener("ioError", xmlLoadError);

Open in new window

Avatar of deepanjandas
deepanjandas
Flag of India image

var xmlnumbers:Number = Math.round( Math.random()*9 ) + 1;

Warm Regards
Deepanjan Das
Avatar of petersego
petersego

ASKER

Sorry, maybe my headline was misleading.
I do not want to load a random xml-file, but a specific xmlfile - if it exist.
So that in the loading-proces, the path is searched for the first file wth the name xmlfile and a number behind it.
If there is one - or several - , it - or the one with the lowest number - is loaded, if not, the loadError-event is executed.

I hope Ive made the question more clear now.
Yes, that is what I have done.

var xmlnumbers:Number = Math.round( Math.random()*9 ) + 1;
var xmlname="xmlfile"+xmlnumbers;
myXML = new XML();
XML_URL = xmlname+".xml";
myXMLURL = new URLRequest(XML_URL);
myxmlLoader = new URLLoader(myXMLURL);
myxmlLoader.addEventListener("complete", myxmlLoaded);
myxmlLoader.addEventListener("ioError", xmlLoadError);

the XML_URL will be something like this - xmlfile1.xml, xmlfile2.xml....till xmlfile10.xml randomly

Warm Regards
Deepanjan Das
Im sorry, i still cant have explained myself correctly.
I have a xml-file named xmlfile5, that i want to be loaded. All that the swf-movie know is that it should load a xml-file, that starts with xmlfile followed by a number. Now, because there is a file named xmlfile5, the swf should load xmlfile5. If there was also a file named xmlfile4, it should load xmlfile4.
But even though I have a file called xmlfile5.xml, it is not loaded. But it should be loaded, since it has a number between 1 and 10.
But the trace shows that the loadErrorEvent is executed.
So i was thinking more in the line of an array of numbers.
Im sorry if I cant explain the question well enough.
Its my bad that I was not able to understand.
Anyways...
Did you check the path.
Where are the xmls located related to your swf and html file?

Warm Regards
Deepanjan Das
Oh, there is nothing wrong with the path.
When I physically writes xmlname as xmlfile5, it does load xmlfile5. But that is the point. The swf-movie will not know that it should load xmlfile5, it only know that it should load files that starts with xmlfile followed by a number. And since I have decided to upload xmlfile5 to the same folder, it should load xmlfile5. If I later on upload xmlfile4 to the folder, the swf-movie should load xmlfile4, not xmlfile5.
okie so do this:

var xmlnumbers:Number = Math.round( Math.random()*9 ) + 1;
var xmlname="xmlfile"+String(xmlnumbers);
myXML = new XML();
XML_URL = xmlname+".xml";

Warm Regards
Deepanjan Das
That will still result in that only one out of ten times it will load xmlfile5. It should load xmlfile5 everytime if xmlfile5 is there.
Did you typecase the number variable like this String(xmlnumbers)?

Warm Regards
Deepanjan Das
petersego. are you still requiring assistance on this?
can you follow up with Deepanjandas or provide a snippet of the code you're done?

if there's a file called xml4.xml how is flashed supposed to know that?
ASKER CERTIFIED SOLUTION
Avatar of petersego
petersego

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok if you're happy with your new approach then close your question please.

why don't you use something like php to go and check for the existence of the file in the folder?
php can return all xml files in the location, pass it to the flash and the flash can load it.
that would be less processor intensive i'm sure.
I managed to figure out this myself