Applicationdomain------- A class of as3, or a technology or concept. Using this technology, you can easily call the server-side SWF and use the methods and variables in the SWF.
Over the past few days, I have been more and more familiar with Flex communication technology, and feel that I am always using some surface applications. I am not familiar with how the entire virtual machine runs a SWF and some internal mechanisms. The language can be artificially encapsulated, but the user's freedom to control is lost. As if it had a memory recycle management, I don't believe that the manual Recycle of C ++ would be inferior to automatic recycle, and put control on a bunch of unknown code, besides, the amount of code to solve the memory problem is not less than the manual release of C ++.
The difference between flex and C ++ is that the language rules are different. framework models, data structures, and ideas are similar.
Code in the previous short program:
Although it is not a good habit to directly access the Code, it is not practical. Because the understanding of application domains, security sandboxes, and other concepts is still very abstract. Write more code
Package COM. works. packages <br/>{< br/> Import flash. display. displayobject; <br/> Import flash. display. sprite; <br/> Import flash. errors. illegaloperationerror; <br/> Import flash. events. event; </P> <p> public class loadswf extends sprite <br/> {<br/> private var Loader: classloader; <br/> private VaR _ inswf: object; <br/> private VaR _ sencename: string; <br/> private var targetclass: string; // class to be called in the program domain <br/> private var recvend: function; // call the external callback function <br/> private var runtimeclassref: class; </P> <p>/** <br/> * @ Param STR <br/> * @ Param myclass <br/> * @ Param callback function of the parent domain, download and call <br/> */<br/> Public Function loadswf (STR: String, myclass: String, callback: function) <br/>{< br/> trace ("loader" + Str); <br/> // addchild (TF); <br/> targetclass = myclass; <br/> recvend = callback; </P> <p> loader = new classloader (); <br/> loader. addeventlistener (classloader. load_error, loaderrorhandler); <br/> loader. addeventlistener (classloader. class_loaded, classloadedhandler); <br/> loader. load (STR ); <br/>}</P> <p>/** <br/> * obtain a SwF instance <br/> * @ return <br/> * /<br/> Public Function get swfobject (): displayobject <br/>{< br/> return displayobject (_ inswf ); <br/>}</P> <p>/** <br/> * obtain the name of the next scene. <br/> * @ return <br/> * <br/> */<br/> Public Function get sencename (): String <br/>{< br/> return _ sencename; <br/>}</P> <p>/** <br/> * download SWF <br/> * @ Param str swf file name <br/> * <br/> */<br/> Public Function loadswf (STR: string): void <br/>{< br/> loader. load (STR ); <br/>}</P> <p>/** <br/> * download error <br/> * @ return <br/> */ <br/> private function loaderrorhandler (E: event): void <br/>{< br/> throw new illegaloperationerror ("cannot load the specified file. "); <br/>}</P> <p>/** <br/> * download completed <br/> * @ return <br/> */ <br/> private function classloadedhandler (E: event): void <br/>{< br/> runtimeclassref = loader. getclass (targetclass); <br/> _ inswf = new runtimeclassref (); <br/> trace ("_ inswf" + _ inswf. tostring (); <br/> enterlocal (targetclass); <br/> This. addchild (displayobject (_ inswf); <br/> _ inswf. addeventlistener (myevent. change, fun ); <br/>}</P> <p>/** <br/> * obtain the current scene name <br/> * @ Param e <br/> * <br/> */<br/> private function fun (E: myevent): void <br/>{< br/> trace ("fun" + e.tar get. tostring (); <br/> _ sencename = E. getsence (); <br/> recvend (); <br/>}</P> <p> Public Function releaseoutlocal (STR: string ): void <br/> {<br/> // _ inswf. releaseoutlocal (STR); <br/> _ inswf. releaseoutlocal (STR); <br/>}</P> <p> Public Function releaseoutnext (STR: string): void <br/>{< br/> _ inswf. releaseoutnext (STR); <br/>}</P> <p> Public Function enterlocal (STR: string ): void <br/> {<br/> trace ("enterlocl" + _ inswf. tostring (); </P> <p> _ inswf. enterlocal (STR); <br/>}</P> <p> Import flash. display. loader; <br/> Import flash. errors. illegaloperationerror; <br/> Import flash. events. event; <br/> Import flash. events. eventdispatcher; <br/> Import flash. events. ioerrorevent; <br/> Import flash. events. securityerrorevent; <br/> Import flash.net. URLRequest; <br/> Import flash. system. applicationdomain; <br/> Import flash. system. loadercontext; </P> <p>/** <br/> * load the SWF loaded in to the application domain of the primary SWF. <br/> * @ author administrator <br/> * <br/> */<br/> class classloader extends eventdispatcher <br/> {<br/> Public Static Var class_loaded: string = "classloaded"; // custom message type <br/> Public Static Var load_error: String = "loaderror"; </P> <p> private var Loader: loader; <br/> private var swflib: string; <br/> private var request: URLRequest; <br/> private var loadedclass: class; </P> <p> Public Function classloader () <br/> {<br/> loader = new loader (); <br/> loader. contentloaderinfo. addeventlistener (event. complete, completehandler); <br/> loader. contentloaderinfo. addeventlistener (ioerrorevent. io_error, ioerrorhandler); <br/> loader. contentloaderinfo. addeventlistener (securityerrorevent. security_error, securityerrorhandler ); <br/>}</P> <p>/** <br/> * load the SWF file <br/> * @ Param lib SWF path <br/> * <br/> */<br/> Public Function load (Lib: string): void <br/>{< br/> swflib = LIB; <br/> request = new URLRequest (swflib); <br/> var context: loadercontext = new loadercontext (); <br/> context. applicationdomain = applicationdomain. currentdomain; <br/> loader. load (request, context ); <br/>}</P> <p>/** <br/> * obtain the specified class in the field. <br/> * @ Param classname <br/> *@ return <br/> */<br/> Public Function getclass (classname: string): class <br/>{< br/> try <br/>{< br/> return loader. contentloaderinfo. applicationdomain. getdefinition (classname) as class; <br/>}< br/> catch (E: Error) <br/>{< br/> throw new illegaloperationerror (classname + "definition not found in" + swflib); <br/>}< br/> return NULL; <br/>}</P> <p> private function completehandler (E: Event): void <br/>{< br/> trace ("loaded" + e.tar get. tostring (); <br/> dispatchevent (new event (classloader. class_loaded); <br/>}</P> <p> private function ioerrorhandler (E: Event ): void <br/>{< br/> dispatchevent (new event (classloader. load_error); <br/>}</P> <p> private function securityerrorhandler (E: Event ): void <br/>{< br/> dispatchevent (new event (classloader. load_error); <br/>}< br/>}