How to refresh uploaded/renamed image?

I am having trouble getting Flash to refresh an image with a new, uploaded image. (Show “image1.jpg”, upload “new.jpg”, rename “new.jpg” to “image1.jpg”, and show “image1.jpg”.) I can get it to work locally, when I publish my file, but things get weird when I try to do this on my server (GoDaddy). (I gave write/execute access to my /images folder.)

Basically, I have a Ball class, which contains a UILoader. I load an external image (image1.jpg) to the loader.

I have a button that lets the user upload a new image to the server, via PHP. Then, I call another PHP file that renames the uploaded file (new.jpg, for example) to the standard image name for the ball (image1.jpg). (I used to unload the image, first, in order to free it up for the PHP rename. Now, it seems to work without unloading.)

The upload and the rename work (verified by several methods), but I cannot get Flash to show the new, renamed image. I know the file is getting renamed, because I see it on the server. If I refresh the page, nothing changes. However, if I close the window and open a new swf, then it shows the new image.

Why can’t I get the image to refresh without closing and opening a new window??? Is this a security issue, or am I missing something about the UILoader?

(Incidentally, if there’s a better way of going about this, such as using something other than UILoader, I’m open to suggestions.)

Here’s my code:

//-------------------------------------------------------------------
// Load thumbnail, and create listenter to show full image
//-------------------------------------------------------------------
ball1_mc.buttonMode = true;
ball1_mc.ballImageLoader.load(new URLRequest(“images/image1.jpg”));
ball1_mc.addEventListener(MouseEvent.CLICK, onBall1Click);

function onBall1Click(event:MouseEvent):void{
fullImageLoader.load(new URLRequest(“images/image1.jpg”));
}

//-------------------------------------------------------------------
// Image upload, rename, and refresh section
//-------------------------------------------------------------------
var fileRef:FileReference = new FileReference();
var newFile:String;

button1_mc.buttonMode = true;
upload_btn.buttonMode = true;
upload_btn.visible = false;

button1_mc.addEventListener(MouseEvent.CLICK, button1Click);
upload_btn.addEventListener(MouseEvent.CLICK, uploadHandler);

fileRef.addEventListener(Event.SELECT,selectHandle r);
fileRef.addEventListener(Event.CANCEL,cancelHandle r);
fileRef.addEventListener(ProgressEvent.PROGRESS,pr ogressHandler);
fileRef.addEventListener(IOErrorEvent.IO_ERROR,ioE rrorHandler);
fileRef.addEventListener(SecurityErrorEvent.SECURI TY_ERROR,securityHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);

function button1Click(event:MouseEvent):void {
fileRef.browse();
newFile = “image1.jpg”;
}
function selectHandler(event:Event):void {
output_txt.text = “Selected File = " + fileRef.name;
output_txt.appendText(”
Name: " + fileRef.name);
output_txt.appendText("
Size: " + fileRef.size);
output_txt.appendText("
Created On: " + fileRef.creationDate);
output_txt.appendText("
Modified On: " +fileRef.modificationDate);
upload_btn.visible = true;
}
function cancelHandler(event:Event):void {
output_txt.text = “Canceled”;
}
function uploadHandler(event:MouseEvent):void {
fileRef.upload(new URLRequest(“http://www.mywebsite.com/project/upload.php”));
}
function progressHandler(event:ProgressEvent):void {
output_txt.text = "file uploading
oprogress (bytes): " + event.bytesLoaded + " / " + event.bytesTotal;
}
function ioErrorHandler(event:IOErrorEvent):void {
output_txt.text = “an IO error occurred”;
}
function securityHandler(event:SecurityErrorEvent):void {
output_txt.text = “a security error occurred”;
}
function completeHandler(event:Event):void {
output_txt.text = “the file has uploaded”;
upload_btn.visible = false;
renameFile(); // Don’t try to rename until after upload complete
}
function renameFile():void {
var request:URLRequest = new URLRequest (“http://www.mywebsite.com/project/rename.php”);
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.oldFile = fileRef.name; // Name of uploaded file
variables.newFile = newFile; // Name to rename to - in this case, “image1.jpg”
request.data = variables;
var loader:URLLoader = new URLLoader (request);
loader.addEventListener(Event.COMPLETE, refreshBall); // After file is renamed, try to force a refresh
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(request); // Call “rename.php”
}
function refreshBall(event:Event):void {
// ball1_mc.ballImageLoader.unload(); // Used to unload to free up file for rename, but seems to work now without unloading
ball1_mc.ballImageLoader.load(new URLRequest(“images/image1.jpg”)); // Still shows old image1 until close/open new window.
}