Forked from: mash's ClassLoader diff:21 Enforcing GPL? I say bullshit. license: invalid points: 1 you can't enforce GPL in the environment like wonderfl and 2 GPL does not solve "software hoarding" problem, it just makes it different. makc3d forked:1favorite:0lines:80license : see code comments modified : 2010-10-19 11:14:03 Embed Tweet // license: invalid // points: 1 you can't enforce GPL in the environment like // wonderfl and 2 GPL does not solve "software hoarding" // problem, it just makes it different. package { import alternativ5.types.Point3D; import flash.display.*; import flash.errors.IllegalOperationError; import flash.events.Event; import flash.text.TextField; public class ApplicationDomainExample extends Sprite { private var loader:ClassLoader; public function ApplicationDomainExample() { loader = new ClassLoader(); loader.addEventListener(ClassLoader.LOAD_ERROR, loadErrorHandler); loader.addEventListener(ClassLoader.CLASS_LOADED, classLoadedHandler); loader.load("http://swf.wonderfl.net/swf/usercode/2/29/29d4/29d413a4e4b26a43e053051e519994e4ff6b426c.swf"); } private function loadErrorHandler(e:Event):void { throw new IllegalOperationError("Cannot load the specified file."); } private function classLoadedHandler(e:Event):void { var FLARParam:Class = loader.getClass("org.libspark.flartoolkit.core.param::FLARParam"); var param:Object /* FLARParam */ = new FLARParam(); var ssize:Object /* FLARIntSize */ = param.getScreenSize(); // oh look, this line makes the code illegal: var point:Point3D = new Point3D (ssize.w, ssize.h, 0); var tf:TextField = new TextField; tf.autoSize = "left"; addChild( tf ); tf.text = "FLARParam.getScreenSize(): " + ssize.toString() + "\nPoint3D.toString():" + point.toString (); } } } import flash.display.Loader; import flash.errors.IllegalOperationError; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IOErrorEvent; import flash.events.SecurityErrorEvent; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; class ClassLoader extends EventDispatcher { public static var CLASS_LOADED:String = "classLoaded"; public static var LOAD_ERROR:String = "loadError"; private var loader:Loader; private var swfLib:String; private var request:URLRequest; private var loadedClass:Class; public function ClassLoader() { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); } public function load(lib:String):void { swfLib = lib; request = new URLRequest(swfLib); var context:LoaderContext = new LoaderContext(); context.applicationDomain = ApplicationDomain.currentDomain; loader.load(request, context); } public function getClass(className:String):Class { try { return loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class; } catch(e:Error) { throw new IllegalOperationError(className + " definition not found in " + swfLib); } return null; } private function completeHandler(e:Event):void { dispatchEvent(new Event(ClassLoader.CLASS_LOADED)); } private function ioErrorHandler(e:Event):void { dispatchEvent(new Event(ClassLoader.LOAD_ERROR)); } private function securityErrorHandler(e:Event):void { dispatchEvent(new Event(ClassLoader.LOAD_ERROR)); } } Code Fullscreen Preview Fullscreen dispatchEvent addEventListener toString load sort new page view favorite forked pv66 forked from: Enforcing GPL? I .. Johnie.Glenn forked:0 favorite:0lines:80 (diff:1)