[AS3] Downloader class

작성자

카테고리:

Downloader.as code

/*
 * This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
 * http://creativecommons.org/licenses/by-nc-sa/3.0/
 */

package	hangunsworld.util{

	import	flash.net.FileReference;
	import	flash.net.URLRequest;
	import	flash.display.DisplayObject;

	/*
	 * Downloader
	 * Downloader class allows you to download a file easily.
	 *
	 * @author: Han Sanghun (http://hangunsworld.com/blog)
	 * @last modified: 2007-03-23
	 * @language version: ActionScript 3.0
	 */

	public class Downloader{

		private var file:FileReference;
		private var req:URLRequest;

		/*
		 * Downloader Constructor
		 */
		public function Downloader(){
			file = new FileReference();
			req = new URLRequest();
		}

		/*
		 * downloadSWF
		 * Download an SWF file that contains the provided DisplayObject.
		 * @param obj A DisplayObject to download.
		 */
		public function downloadSWF(obj:DisplayObject):void{
			req.url = obj.loaderInfo.url;
			file.download(req);
		}

		/*
		 * downloadURL
		 * Download a specific file.
		 * @param url An URL of a file to be downloaded.
		 */
		public function downloadURL(url:String):void{
			req.url = url;
			file.download(req);
		}

	}

}

import hangunsworld.util.Downloader;

var dw:Downloader = new Downloader();
dw.downloadURL("http://somedomain.com/somefile.as");
dw.downloadSWF(this);

코멘트

“[AS3] Downloader class”에 대한 댓글 1개

  1. Downloader class was modified….

    Downloader 클래스의 패키지를 com.hangunsworld.util 에서 com.hangunsworld.net 으로 변경하였습니다. 아무래도 util 보다는 net 패키지에 있는 것이 더 적당한 것 같아서요.
    그리고 addEventListener, removeEventListe…