mApplication.downloadFile()

Availability

Windows: Flash 8 or 9 AS2.0 SWF + mProjector 3.0; Windows 98/ME/NT Support: Flash 7 SWF + mProjector 2.0;

Macintosh: Flash 8 or 9 AS2.0 SWF + mProjector 2.0; replacing mProjector 1.0 async

Usage

mApplication.downloadFile(fileName:String, URL:String, progressObject:Object, progressFunction:String) : Number

Parameters

fileName - Name of local file where the downloaded file will be saved. If no path is specified, the working directory is used.

URL - URL of the remote file to be downloaded.

progressObject - Optional object that will be used as this of the progress function.

progressFunction - Progress function that will be called periodically during the download.

Returns

A number.; ; WINDOWS ONLY: The number is a download session id. You can abort the download at any time by calling the xref=mApplication.abortFunction() function, passing the downloadSessionId as a parameter.

The Mac version has no return value.

Description

Method; Downloads a remote file onto the local computer.

Example

The following example downloads a random image from a server.

var localFileName = mApplication.getFolder()+mSystem.getPathDelimiter()+"image1.jpg";
var remoteFileName:String = "";
var downloadSuccess:Boolean;
var downloadStr:String = "---";

downloadFile_btn.onPress = function() {
	if (isConnected) {
		downloadStr = "downloading file...";
		remoteFileName = "http://www.screentime.com/temp/"+randRange(1, 12)+".jpg";
		mApplication.downloadFile(localFileName, remoteFileName, _root, _root.onProgress);
	}
};

function randRange(min:Number, max:Number):Number {
	var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
	return randomNum;
}

_root.onProgress = function(read:Number, total:Number) {
	downloadStr = "downloading file...";
	mApplication.trace("onProgress read: " + read + " total: " + total);
	if (total == 0) {
		downloadSuccessful = false;
		downloadStr = "download failed.";
	} else if (read == total) {
		if (mFile.fileExists(localFileName)) {
			downloadSuccessful = true;
			image_mc._xscale = 20;
			image_mc._yscale = 18;
			image_mc.loadMovie(localFileName);
			downloadStr = "download successful.";
		} else {
			downloadSuccessful = false;
			downloadStr = "download failed.";
		}
	}
}

See Also

mApplication.abortFunction(), mApplication.getHostAddress(), mApplication.checkNetConnection(),

Code Examples

Check Connection and Download File, mProjector Class Basics -- mApplication, SWF Desktop Helper (Windows)