EDIT Well, it seems I was an idiot and it was sending it back as a string :trout:. I can’t delete the post, so thought I should edit here to stop people wasting their time.
I seem to be having a really confusing issue here, with the deleteXML.deleted if statement at the top of the onLoad_Delete_Level. Basically, the two ExternalInterface.call methods (which are just traces in Firebug) that sandwich the if statement are both tracing deleteXML.deleted as false when appropriate but the if statement between them is acting as if it is true when it should go to the else statement.
At first I thought it I was being an idiot and it was because the echo I am sending back from the PHP isn’t a Boolean, but I tried to format is as a string too within the if statement but that didn’t seem to work either. I didn’t think this belonged in the PHP forum either as I’m pretty sure that isn’t the issue here.
private function Delete_Level(levelNum:Number):Void {
levelToDelete = levelNum;
if (levelNum != currentLevel) {
_root[PROMPT_WINDOW].inner[PROMPT_BTN + "_yes"].enabled = _root[PROMPT_WINDOW].inner[PROMPT_BTN + "_no"].enabled = false;
deleteXML = new LoadVars();
deleteXML.directory = "../" + LEVEL_DIRECTORY;
deleteXML.fileName = levelList[levelNum][1];
deleteXML.extension = ".xml";
deleteXML.sendAndLoad("php/deleteFile.php", deleteXML, "POST");
deleteXML.onLoad = Delegate.create(this, onLoad_Delete_Level);
} else {
Attach_Prompt_Window(ERROR_LEVEL_DELETE_CURRENT, 1, null, null);
}
}
private function onLoad_Delete_Level() {
ExternalInterface.call("console.log", "Level Deleted " + deleteXML.deleted);
if (deleteXML.deleted) {
ExternalInterface.call("console.log", "Level Deleted " + deleteXML.deleted);
levelList.splice(levelToDelete, 1);
if (levelToDelete < currentLevel) {
currentLevel--;
}
Update_Level_List();
Remove_Clip_After_Anim(_root[PROMPT_WINDOW]);
} else {
ExternalInterface.call("console.log", "Level not Deleted " + deleteXML.deleted);
Attach_Prompt_Window(ERROR_ITEM_MOVE, 1, null, null);
}
}
<?php
//Deletes the file name String sent in the variables.
$dir = $_POST['directory'];
$fn = $_POST['fileName'];
$ext = $_POST['extension'];
$filename = $dir.$fn.$ext;
if(file_exists($filename)){
unlink($filename);
echo "&deleted=true&"; //Lets Flash access the deleted property using .deleted
} else {
echo "&deleted=false&";
}
?>
Any help is greatly appreciated, sorry about the scrolling :(,
Mental.