STF.downloadFile()

Availability

SupportPCMacPackage
ActionScript 3.0

3.9.2

3.9.2

stm.screentime.STF

ActionScript 2.0

3.0

3.0

global

  * Add the Screentime screensaver component to your Flash FLA or Flex project before using Screentime classes.

Usage

STF.downloadFile(fileName:String, URL:String) : Boolean

Parameters

fileName - Name of local file (including relative path from the screen saver swf) where the downloaded file will be saved. If the relative path does not exist, it will be created.

The screen saver swf is located in the screen saver's working directory. If you need the file in a location other than the working directory, download it and copy it to the desired location using STF.copyFile().

URL - URL of the remote file to be downloaded.

Returns

A boolean. This value is returned as a parameter to the registered callback. See the example below or STF.registerCallBack() for more information on callbacks and Screentime asynchronous command model.

Description

Method; Downloads a remote file onto the local computer.

ActionScript 3.0 Example:

This example

// This example dynamically create a UI with buttons and     //
// text fields  .                                             //

// IMPORTANT- in order for this sample code to work in Flash 
// you must add the Button Component to your Library.
// You must also add the Screentime Screensaver Component.

import stm.screentime.STF;

import fl.controls.Button;

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;

var newline:String = "\n";

// create the text fields
var heading:TextField = createTextField(10, 180, 200, 20, false, "Event Log.");
var event_log_txt:TextField = createTextField(10, 200, 300, 100, true, "");

// create the buttons
var checkNetConnection_btn:Button = createButton(200, 10, 160, 20, "Check Internet Connection");
var downloadFile_btn:Button = createButton(200, 35, 160, 20, "Download File");

////////////////////////////////////////////////////////
///       Test for Internet Connection               ///
///////////////////////////////////////////////////////

var isConnectedStr:String = "---";
var isConnected:Boolean = false;

// define callback function function
function onCheckNetConnectionReturn(returnValue:Boolean):void {
	isConnected= returnValue;
	if (isConnected) {
		isConnectedStr = "true";
	} else {
		isConnectedStr = "false";
	}
	event_log_txt.text += isConnectedStr + newline;
}


// register callback function
STF.registerCallBack("checkNetConnection", onCheckNetConnectionReturn, this);

//call method -- check for a connection to the internet
function checkNetConnection_btn_click(e:Event):void {
	STF.checkNetConnection();
}

checkNetConnection_btn.addEventListener(MouseEvent.CLICK,checkNetConnection_btn_click );


///////////////////////////////////////////////////////
///     Demonstrate mApplication.downloadFile()     ///
///////////////////////////////////////////////////////

//var localFileName:String = STF.getFolder()+"/image1.jpg";
var localFileName:String = "test.jpg";
var remoteFileName:String = "http://www.screentime.com/assets/templates/screentimemedia/images/box_mprojector.png";
var downloadSuccess:Boolean;
var downloadStr:String = "---";
var sessionID:Boolean;


function downloadFile_btn_click(e:Event):void {
	if (isConnected) {
		event_log_txt.text = "downloading file..." + newline;
		STF.downloadFile(localFileName, remoteFileName);
	} else {
		event_log_txt.text = "Interent not online, try clicking Check Connection Button" + newline;

	}
}
downloadFile_btn.addEventListener(MouseEvent.CLICK, downloadFile_btn_click);


function onDownloadFileReturn(success:Boolean):void {
	if (success) {
		event_log_txt.text += "download succeeded..." + newline;
		loadJPEG("test.jpg");
	} else {
		event_log_txt.text += "download failed..." + newline;
	}
}

STF.registerCallBack("downloadFile", onDownloadFileReturn, this);


///////////////////////////////////////////////////////
///             JPG Loader Function                 ///
///////////////////////////////////////////////////////

function loadJPEG(path:String):void {

	var imageURLRequest:URLRequest = new URLRequest(path);
	var myImageLoader:Loader = new Loader();
	myImageLoader.load(imageURLRequest);

	myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
	function imageLoaded(e:Event):void {
		var myBitmapData:BitmapData = new BitmapData(myImageLoader.width, myImageLoader.height);
		myBitmapData.draw(myImageLoader);
		var myBitmap:Bitmap = new Bitmap;
		myBitmap.bitmapData = myBitmapData;
		addChild(myBitmap);
	}
}

///////////////////////////////////////////////////////
/// Generic utility functions to create text fields ///
///  and Buttons                                    ///
///////////////////////////////////////////////////////

function createTextField(x:Number, y:Number, width:Number, height:Number, border:Boolean, intialText:String):TextField {
	var result:TextField = new TextField();
	result.x = x;
	result.y = y;
	result.width = width;
	result.height = height;
	result.border = border;
	result.text = intialText;
	addChild(result);
	return result;
}

function createButton(x:Number, y:Number, width:Number, height:Number, name:String):Button {
	var result:Button = new Button();
	result.x = x;
	result.y = y;
	result.width = width;
	result.height = height;
	result.label = name;
	addChild(result);
	return result;
}

ActionScript 2.0 Example:

This example

// Important - in order for this sample code to work in Flash 
// you must add the SimpleButton Component to your Library.
// You must also add the Screentime Screensaver Component.

var newline:String = "\n";

// create the text fields
var heading:Label 		= createLabel(10, 180, 200, 20, "Event Log.");
var event_log_txt:TextArea 	= createTextArea(10, 200, 400, 100, true, "");

// create the buttons
var checkNetConnection_btn:MovieClip = createSimpleButton(10, 10, 160, 20, "Check Internet Connection");
var downloadFile_btn:MovieClip 		 = createSimpleButton(10, 35, 160, 20, "Download File");

////////////////////////////////////////////////////////
///       Test for Internet Connection               ///
///////////////////////////////////////////////////////

var isConnectedStr:String = "---";
var isConnected:Boolean = false;

// define callback function function
function onCheckNetConnectionReturn(returnValue:Boolean) {
	isConnected= returnValue;
	if (isConnected) {
		isConnectedStr = "true";
	} else {
		isConnectedStr = "false";
	}
	event_log_txt.text += isConnectedStr + newline;
}


// register callback function
STF.registerCallBack("checkNetConnection", onCheckNetConnectionReturn, this);

//call method -- check for a connection to the internet
checkNetConnection_btn.onRelease = function() {
	STF.checkNetConnection();
}


///////////////////////////////////////////////////////
///     Demonstrate mApplication.downloadFile()     ///
///////////////////////////////////////////////////////

//var localFileName:String = STF.getFolder()+"/image1.jpg";
var localFileName:String = "test.jpg";
var remoteFileName:String = "http://www.screentime.com/assets/templates/screentimemedia/images/box_mprojector.png";
var downloadSuccess:Boolean;
var downloadStr:String = "---";
var sessionID:Boolean;


downloadFile_btn.onRelease = function() {
	if (isConnected) {
		event_log_txt.text = "downloading file..." + newline;
		STF.downloadFile(localFileName, remoteFileName);
	} else {
		loadJPEG(remoteFileName);
		event_log_txt.text = "Interent not online, try clicking Check Connection SimpleButton" + newline;

	}
}

function onDownloadFileReturn(success:Boolean) {
	if (success) {
		event_log_txt.text += "download succeeded..." + newline;
		loadJPEG("test.jpg");
	} else {
		event_log_txt.text += "download failed..." + newline;
	}
}

STF.registerCallBack("downloadFile", onDownloadFileReturn, this);


///////////////////////////////////////////////////////
///             JPG Loader Function                 ///
///////////////////////////////////////////////////////

function loadJPEG(path:String) {

	var image_mc = createEmptyMovieClip();
	// Creates a movie clip to hold the container.
	var image_mc:MovieClip = this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
	// Loads an image into image_mc.
	image_mc._x = 200;
	image_mc._y = 10;
	image_mc.loadMovie(path);

}

///////////////////////////////////////////////////////
/// Generic utility functions to create text fields ///
///  and SimpleButtons                                    ///
///////////////////////////////////////////////////////

function createTextArea(x:Number, y:Number, width:Number, height:Number, border:Boolean, intialText:String):TextArea {
	
	var depth = this.getNextHighestDepth();
	var temp_txt:TextArea = createClassObject(TextArea, "textField" + depth,depth,{text: intialText});
	temp_txt.move(x, y);
	temp_txt.setSize(width, height);
	temp_txt.text = intialText;
	temp_txt.setStyle(); 
	return temp_txt;
	
}

function createLabel(x:Number, y:Number, width:Number, height:Number, intialText:String):Label {
	
	var depth = this.getNextHighestDepth();
	var temp_txt:Label = createClassObject(Label, "textField" + depth,depth,{text: intialText});
	temp_txt.move(x, y);
	temp_txt.setSize(width, height);
	temp_txt.text = intialText;
	return temp_txt;
	
}

function createSimpleButton(x:Number, y:Number, width:Number, height:Number, label_str:String):MovieClip {
	
    var depth:Number = this.getNextHighestDepth();
    var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
    var mcFmt:TextFormat;

    mc.beginFill(0xCCCCCC);
	mc.moveTo(x, y)
    mc.lineTo(x, y + height);
    mc.lineTo(x + width, y + height);
    mc.lineTo(x + width, y);
    mc.lineTo(x, y);

    mcFmt = new TextFormat();
    mcFmt.align = "center";
    mcFmt.bold = true;

    mc.createTextField("mcTxt", depth, x, y, width, height);
    mc.mcTxt.text = label_str;
    mc.mcTxt.setTextFormat(mcFmt);

    return mc;
}

See Also

STF.checkNetConnection()

 

viagra internet compare cialis prices uk discount cigarettes palm desert