PDA

View Full Version : Can't get URL Loader to update



Ricky55
January 8th, 2009, 07:15 PM
Hi

I have a button on my page that when clicked allows users to save an high res version of the image they are currently viewing, I using the File Reference to achieve this and it works fine.

I need to change the path the File Ref users each time a new movie has loaded, I currently have this code



var fileRef:FileReference = new FileReference();
var thePath:String = "http://www.domain.co.uk/images/calvaApple.jpg";
var fileURL:URLRequest = new URLRequest(thePath);

saveImage_btn.addEventListener(MouseEvent.CLICK, saveFile);

function saveFile(event:Event):void {
fileRef.download(fileURL);
}



When the buttons are clicked to load in the external images as well as loading in the images I am also setting the path to relevant image. Like this:

thePath = "http://www.domain.co.uk/images/whiteAsh.jpg";

When I trace the path out using a test button the path traces correctly but the file ref just refuses to update and just constantly tries to save the original image.

Can any one point me in the right direction with this please.

Thanks in advance.

You can see the page here if it helps explain what I mean.
http://www.spenvalleykitchens.co.uk/products/doors/ashby.html

Ricky

scottc
January 9th, 2009, 02:48 AM
a caching issue?

thePath = "http://www.domain.co.uk/images/whiteAsh.jpg?r=" + Math.random();
Adding a random number on the end as a get variable is a quick and easy fix for caching issues.

You can use a time variable to guarantee its a different number each time.

Ricky55
January 9th, 2009, 03:05 PM
Hi Scott, I tried that but it still didn't work again the path traces correctly but when I click the save image button it still only wants to save the original image.

What was that timer method?

Is this possible?

Ricky55
January 9th, 2009, 03:10 PM
These are the paths that i can trace out when I click on a dummy test button, these are correct but like I say the File Ref still only points to the original file.

You can see the page here
http://www.spenvalleykitchens.co.uk/products/doors/ashby.html

Its just the calva apple and white ash that I've tried to setup so far.

These are the paths that trace correctly, how can this not be working when the paths are correct?

http://www.spenvalleykitchens.co.uk/flash_work/images/highResDoors/ashby/ashby_calvaApple.jpg?r=0.9228854859247804

http://www.spenvalleykitchens.co.uk/flash_work/images/highResDoors/ashby/ashby_whiteAsh.jpg?r=0.38084419444203377

Brisa
January 9th, 2009, 03:19 PM
Did you try setting thePath=""; to force it to refresh as in

function saveFile(event:Event):void {
fileRef.download(fileURL);
thePath="";
}

?

scottc
January 9th, 2009, 03:24 PM
Oh sorry, i misunderstood the question. I thought you were having caching issues.

So you have a high and low res version of each picture?
But download link sending the low res when it should be sending the high res one?

If so, just correct the file path for the download link.

Ricky55
January 9th, 2009, 09:19 PM
No its not that either mate, when I click the save high res image button it points to the high res image but it points to the same image every time even when the path has been modified and is tracing correctly. The file ref just refuses to except the new path.

If you have look at the page I have setup the Calva Apple and White Ash but even when you are viewing the white ask the save icon still wants to save the Calva Apple.

Brisa, I did try that and even that didn't work but its not that the path isn't updating because it is, if I trace out the path it changes correctly but for some reason the file ref will only save the first image path its been fed. Is there any way to say to the file ref use the new path?

Can file refs accept event listeners, I wonder if I could add on load complete check to see what the path is.

Ricky55
January 9th, 2009, 10:48 PM
Got it working, I just place the whole file ref in the function



function saveFile(event:Event):void {
var fileRef:FileReference = new FileReference();
var fileURL:URLRequest = new URLRequest(thePath);
fileRef.download(fileURL);
}


Thanks for your help