PDA

View Full Version : copyTo() function not working?


RossMalan
04-21-2008, 08:14 AM
Hi
I'm new to actionscript and have ran across an error which makes no sense to me.

My code:

function backupFile()
{
try
{
var sourceFile:FileReference = new FileReference();
sourceFile = File.applicationStorageDirectory.resolvePath("IRPFile.db");
var dest:FileReference = new FileReference();
dest = File.documentsDirectory.resolvePath("C:\Documents and Settings\ross.malan\Desktop\IPRFile.db");
var boo:Boolean = true;
dest.copyTo(sourceFile, boo);
}


It keeps throwing a 1061 error when I compile, but I set my code up pretty much exactly as it was in the adobe documentation.
Any help please?

amarghosh
04-21-2008, 09:05 AM
where did u get copyTo method from? adobe's documentation of FileReference class doesn't contain such a method.
r u sure u r using AS3?
which package contains the File class?

wvxvw
04-21-2008, 10:08 AM
This should be AIR code, are you sure you're not trying to do it with Flash/Flex? May be try posting it in AIR (Apollo) forum, you'll get more help there...

FlexDemons
11-05-2008, 06:45 AM
Hi,

you can use File object instead of FileReference.

for example:

var fl:File=e.target.file;
var newFile:File=File.CreateTempFile();

newFile.nativePath="C:\\xmlDemo";
newFile=newFile.resolvePath("Testfile.jpg");

fl.copyTo(newFile,true);

the above code will copy the file to the newfile location with the name Testfile.jpg. The above example is just for explanation so you can modify as accordingly.
with regards
FlexDemons