Loader系 [ActionScript3.0]

XMLロード

private var _loader:URLLoader;

private function sample() 
{
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.net.URLVariables;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoaderDataFormat;
	import flash.events.Event;

	_loader = new URLLoader();

	var url:String = "http://aaa/aaa.xml";
	var request:URLRequest = new URLRequest(url);
	try {
		_loader.load(request);
	} catch (error:Error) {
		trace("Unable to load requested document.");
	}

	_loader.addEventListener(Event.COMPLETE, completeHandler);
}

private function completeHandler(e:Event):void 
{
	var xml:XML = XML(_loader.data);
}

PHP

private var _loader:URLLoader;

private function sample() 
{
	var url:String = "http://aaa/aaa.php";
	var request:URLRequest = new URLRequest(url);
	request.method = URLRequestMethod.POST;

	var variables:URLVariables = new URLVariables();
	variables["sample"] = "sample";

	request.data = variables;

	_loader = new URLLoader();
	_loader.dataFormat = URLLoaderDataFormat.TEXT;
	_loader.load(request);

	_loader.addEventListener(Event.COMPLETE, responseHandler);
}

private function completeHandler(e:Event):void 
{
	var xml:XML = XML(_loader.data);
}

画像ロード

private var _loader:Loader;

private function sample() 
{
	_loader = new Loader();
	var url:String = "http://aaa/aaa.jpg";
	var request:URLRequest = new URLRequest(url);
	addChild(loader);

	try {
		loader.load(request);
	} catch (error:Error) {
		trace("Unable to load requested document.");
	}
	_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

}

public function completeHandler(e:Event):void 
{
	//var bmp:Bitmap = Bitmap( _loader.content);
	//bmp.smoothing = true;

	//_loader.unload();
}

SWFロード

親 SWF

package classes
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.ProgressEvent;

	import flash.display.Loader;
	import flash.system.LoaderContext;
	import flash.system.ApplicationDomain;
	import flash.net.URLRequest;

	public class LoadChild
	{
		private var _loader:Loader;
		private var _child:MovieClip;

		private function startLoad() 
		{
			_loader = new Loader();
			var url:String = "child.swf";
			var request:URLRequest = new URLRequest(url);

			var context:LoaderContext = new LoaderContext();
			context.applicationDomain = ApplicationDomain.currentDomain;

			try {
				_loader.load(request, context);
			} catch (error:Error) {
				trace("Unable to load requested document.");
			}
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
			_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
		}

		private function progressHandler(e:ProgressEvent):void
		{
		}

		private function completeHandler(e:Event):void
		{
			addChild(_loader);


			// 子 SWF の helloWorld メソッドにアクセスする
			_child = _loader.content as MovieClip;
			trace(_child.helloWorld("hoge"));

			//_loader.unload();
		}
	}
}

子 SWF

ドキュメントクラス。

package
{
	import flash.display.MovieClip;

	public class Child extends MovieClip
	{
		public function GoogleMap()
		{
			addEventListener(Event.ADDED_TO_STAGE, initialize);
		}

		private function initialize(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, initialize);
		}

		public function helloWorld(value:String):String
		{
			var result:String = "Hello !" + value + " ! ";
			return result;
		}
	}
}

参考


Comment



Counter: 7352, today: 1, yesterday: 2

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-09-24 (火) 14:56:01 (1280d)