Okay, so I’m having a bit of a problem creating an array of names read out of an XML file.
Here’s my code
var picture01_URL:URLRequest = new URLRequest("picture01.jpg");
var picture01_Loader:Loader = new Loader();
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var myString:String;
var filenameArray:Array = new Array();
var substringPlace:Number;
var stringEnd:Number;
var newString:String;
xmlLoader.load(new URLRequest("page1.xml"));
picture01_Loader.load(picture01_URL);
//xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.addEventListener(Event.COMPLETE, loadFiles);
stage.addEventListener(MouseEvent.CLICK, checkArray);
addChild(picture01_Loader);
picture01_Loader.x = picture01_Loader.width/2;
picture01_Loader.y = picture01_Loader.height/2;
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
myString = xmlData;
//trace(xmlData);
//The .split function, used like this, can be used to name the files.
//trace(myString.split(".jpg").join(".jpg|"));
}
function loadFiles(e:Event):void {
xmlData = new XML(e.target.data);
myString = xmlData;
}
function checkArray(e:MouseEvent):void {
//Get a new file name
myString = myString.split(".jpg").join(".jpg%");
substringPlace = myString.search("%");
stringEnd = myString.search("&");
//This line clears from any spot to the beginning
//myString = myString.slice(substringPlace, stringEnd);
newString = myString.slice(0, substringPlace);
filenameArray.push(newString);
//trace("Substring Place = " + substringPlace);
//trace("String End = " + stringEnd);
trace("New String = " + newString);
//Check file against files already in the Array
for each(var arrayFileNames:String in filenameArray) {
if (arrayFileNames == newString) {
myString = xmlData;
myString = myString.split(newString);
trace("My String = " + myString);
}
else {
filenameArray.push(newString);
}
}
//Load the new file on to the stage
//Add the new file name to the array
trace("File Name Array = " + filenameArray);
}
Now, whenever I run that, I get this error:
Description: 1067: Implicit coercion of a value of type Array to an unrelated type String.
Source: myString = myString.split(newString);
I’m can’t figure out what the problem is. The first time I use the .split property on the myString variable, it works no problem. But in that for each loop, it keeps giving me that error.
Any advice?
1076