// forked from mtok's 外部SWFからのクラス定義の取り出し /* fetch class definition from external swf author: motoki matsumoto email: mtmotoki(at)gmail.com */ package { import flash.text.TextField; import flash.display.*; import flash.events.*; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.utils.getQualifiedClassName; [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="24")] public class DynamicClassLoading extends MovieClip { private var output:TextField; private var avatar:Loader; private var _textField : TextField = new TextField(); public function DynamicClassLoading() { initOutput(); println('Construct ' + getQualifiedClassName(this)); addEventListener(Event.ADDED_TO_STAGE, addedToStage); addEventListener(MouseEvent.CLICK, clickHandler); _textField.wordWrap = true; _textField.textColor = 0xffffff; _textField.border = true; _textField.borderColor = 0x888800 _textField.textColor = 0xffffff; _textField.selectable = false; _textField.width = 445; _textField.height = 100; _textField.x = 10; _textField.y = 350; _textField.text = ""; addChild(_textField); } public function init():void { avatar = new Loader(); var req:URLRequest = new URLRequest("http://www23.tok2.com/home/ppc/avatar.swf"); //var req:URLRequest = new URLRequest("http://img.atgames.jp/event/campaign/200904/img/090403_ohanamiCP/01.swf"); avatar.load(req); avatar.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); } private function completeHandler(e:Event):void { addChild(avatar); avatar.x = 100; avatar.y = 100; _textField.appendText(avatar.contentLoaderInfo.contentType + "\n"); if(avatar.contentLoaderInfo.contentType == "application/x-shockwave-flash") { _textField.appendText("version:" + avatar.contentLoaderInfo.swfVersion.toString() + "\n"); } _textField.appendText("hoge"); //avatar.content.avatar.sit(); } private function clickHandler(event:MouseEvent):void { //avatar.sit(); } private function addedToStage(e:Event):void { removeEventListener(e.type, arguments.callee); stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; init(); } //////////////// // 出力 /////////////// private function initOutput():void { var margin:Number = 10; addChild(output = new TextField()); output.selectable = false; output.multiline = true; output.width = stage.stageWidth - margin * 2; output.height = stage.stageHeight - margin * 2; } public function print(... args):void { output.appendText(args.join(", ")); } public function println(... args):void { output.appendText(args.join(", ")); output.appendText("\n"); } } } /* 書いてみたもののあんまり役に立たなそう(笑) */ import flash.events.Event; import flash.events.HTTPStatusEvent; import flash.events.IOErrorEvent; import flash.events.SecurityErrorEvent; import flash.events.EventDispatcher; import flash.display.Loader; import flash.display.LoaderInfo; import flash.events.ProgressEvent; import flash.system.LoaderContext; import flash.net.URLRequest; import flash.utils.getQualifiedClassName; import flash.system.ApplicationDomain; import flash.system.SecurityDomain; class ClassLoader extends EventDispatcher { private var _applicationDomain:ApplicationDomain; public function ClassLoader(applicationDomain:ApplicationDomain) { if (applicationDomain == null) { throw new ArgumentError("applicationDomain is null"); } _applicationDomain = applicationDomain; } public function loadSWF(req:URLRequest):void { var l:Loader = new Loader(); var context:LoaderContext = new LoaderContext(true, _applicationDomain, SecurityDomain.currentDomain); l.load(req, context); l.contentLoaderInfo.addEventListener(Event.COMPLETE, redirectEvent); l.contentLoaderInfo.addEventListener(Event.OPEN, redirectEvent); l.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusEventHandler); l.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler); } private function redirectEvent(e:Event):void { var event:Event = new Event(e.type); dispatchEvent(event); EventDispatcher(e.target).removeEventListener(e.type, arguments.callee); } private function httpStatusEventHandler(e:HTTPStatusEvent):void { var event:HTTPStatusEvent = new HTTPStatusEvent(e.type, false, false, e.status); dispatchEvent(event); EventDispatcher(e.target).removeEventListener(e.type, arguments.callee); } private function securityErrorHandler(e:SecurityErrorEvent):void { var event:SecurityErrorEvent = new SecurityErrorEvent(e.type, false, false, e.text); dispatchEvent(event); EventDispatcher(e.target).removeEventListener(e.type, arguments.callee); } private function progressHandler(e:ProgressEvent):void { var event:ProgressEvent = new ProgressEvent(e.type, false, false, e.bytesLoaded, e.bytesTotal); dispatchEvent(event); EventDispatcher(e.target).removeEventListener(e.type, arguments.callee); } public function getClass(name:String):Class { var cls:Class = _applicationDomain.getDefinition(name) as Class; if (cls == null) { throw new Error("Can't find class definition"); } return cls; } public function get applicationDomain():ApplicationDomain { return _applicationDomain; } } forked from: 外部SWFからのクラス定義の取り出し