Post-compilation patch download link for this article http://download.csdn.net/source/1908278
Multi-module application, each load of a module will repeatedly load the RSL used by the module, now add a
private static var loadedrsls:dictionary = new Dictionary (); To save whether it is loaded
Mx.core.RSLListLoader
//ADOBE SYSTEMS Incorporated// Copyright Adobe Systems Incorporated//All rights Reserved. Notice:adobe permits you to use, modify, and distribute this file//In accordance with the terms of the license AG Reement accompanying it. Modify SDK code free RSL repeat load, boost module load performance////////////////////////////////////////////////////////////////////////////////// Package Mx.core {import flash.events.IEventDispatcher; import flash.events.Event; import flash.utils.Dictionary; [Excludeclass]/** * @private * Utility class for loading a list of RSLs. * <p>a List of Cross-domain RSLs and a L IST of regular RSLs * can be loaded using the This utility.</p> */public class Rsllistloader {//---------------------- ----------------------------------------------------////Constructor////---------------------------------------- ----------------------------------/** * Constructor. * * @param rsllist Array of RSLs to load. * Each entry in the array is of type Rslitem or Cdrslitem. * The RSLs'll is loaded from index 0 to the end of the array. */Public Function Rsllistloader (Rsllist:array) {super (); this.rsllist = rsllist;}//--------------------------------- -----------------------------------------////Variables////----------------------------------------------------- ---------------------/** * @private * The index of the RSL being loaded. */private var currentindex:int = 0; /** * @private * The list of RSLs to load. * Each entry is of type Rslnode or Cdrslnode. */private var rsllist:array = []; /** * @private * supplied by caller. */private Var chainedprogresshandler:function; /** * @private * supplied by caller. */private Var chainedcompletehandler:function; /** * @private * supplied by caller. */private Var chainedioerrorhandler:function; /** * @private * supplied by caller. */private Var chainedsecurityerrorhandler:function; /** * @private * supplied by caller. */Private VAR chainedrslerrorhandler:function; /** * Save loaded RSL flag */private static var loadedrsls:dictionary = new Dictionary (); --------------------------------------------------------------------------////Methods////-------------------- ------------------------------------------------------/** * Loads The RSLs in this list object. * * <p>this function accepts listeners to observe events * This result from loading an RSL. * The function must is of the form required by a listener function * passed to <code>ieventdispatcher.addeventlisten ER ();</code> * When a event is received, the RSL that generated * This event can be found by calling * <CODE&G T;rsllistloader.getitem (GetIndex ());</code></p> * * @param progresshandler receives Progressevent.progress events. * May is null. * * @param completehandler receives event.complete events. * May is null. * * @param ioerrorhandler receives ioerrorevent.io_error events. * May is null. * * @param Securityerrorhandler * Receives SECURITYERROREVENT.SECURITY_ERROR events. * May is null. * * @param rslerrorhandler receives rslevent.rsl_error events. * May is null. */Public Function load (progresshandler:function, completehandler:function, Ioerrorhandler:function, Securityerrorhandler:function, rslerrorhandler:function): void {chainedprogresshandler = ProgressHandler; Chainedcompletehandler = Completehandler; Chainedioerrorhandler = Ioerrorhandler; Chainedsecurityerrorhandler = Securityerrorhandler; Chainedrslerrorhandler = Rslerrorhandler; Currentindex =-1; So first loaded item would be index 0 loadnext (); }/** * Increments the current index and loads the next RSL. */Private Function loadnext (): void {if (!isdone ()) {currentindex++;//Load the current RSL. if (Currentindex < RSLL Ist.length) {//Load RSL and has the RSL loader chain the/Events our internal events handler or the chained/events Handler if we don ' t care about them. Trace ("Load RSL URL:" + (Rsllist[currentindex] as Rslitem). URL); if (loadedrsls[(Rsllist[currentindex] as Rslitem). url] = = null) {Rsllist[currentindex].load (Chainedprogresshandler, Listcompletehandler, Listioerrorhandler, Listsecurityerrorhandler, Chainedrslerrorhandler); Loadedrsls[(Rsllist[currentindex] as Rslitem). url] = true; } else {loadnext ();//Skip already Loaded RSLs}}}}/** * Gets an RSL from the list of RSLs. * * @param index A zero- Based index into the list of RSLs. * * @return The current item @ <code>index</code> in the list, * or <co De>null</code> If there is no item at that index. */Public Function GetItem (index:int): Rslitem {if (Index < 0 | | index >= RSLLIST.LENGTH) return null; return Rsllis T[index]; }/** * Gets The index of the currently loading RSL. * * @return The index of the currently loading RSL. */Public Function getindex (): int {return currentindex;}/** * Gets The total number of RSLs in this object. * When the load () method is called the RSLs would be loaded. * * @return The Total number of RSLs in this object */Public Function GetItemCount (): int {return rsllist.length;}/** * Tests if all t He RSLs is done loading. * * @return <code>true</code> If all the RSLs has been loaded, * <code>false</code> otherwise. */Public Function IsDone (): Boolean {return currentindex >= rsllist.length;}//------------------------------------ --------------------------------------////Event Handlers////--------------------------------------------------- -----------------------/** * @private */Private Function Listcompletehandler (event:event): void {//Pass event to extern Al Listener. if (Chainedcompletehandler! = null) Chainedcompletehandler (event); Load the next RSL. Loadnext (); }/** * @private * * * Private Function Listioerrorhandler (event:event): void {//Pass event to external listener. if (chaine Dioerrorhandler = null) Chainedioerrorhandler (event); }/** * @private * * * Private Function Listsecurityerrorhandler (event:event): void {//Pass event to external listener. if (Chainedsecurityerrorhandler! = null) Chainedsecurityerrorhandler (event); } } }
Mx.core.RSLItem
//ADOBE SYSTEMS Incorporated// Copyright Adobe Systems Incorporated//All rights Reserved. Notice:adobe permits you to use, modify, and distribute this file//In accordance with the terms of the license AG Reement accompanying it. Package Mx.core {Import Flash.display.Loader; Import flash.events.Event; Import flash.events.ErrorEvent; Import flash.events.ProgressEvent; Import flash.events.IOErrorEvent; Import flash.events.SecurityErrorEvent; Import Flash.net.URLRequest; Import Flash.system.LoaderContext; Import Flash.system.ApplicationDomain; Import Flash.system.LoaderContext; Import flash.system.Security; Import Flash.system.SecurityDomain; Import Flash.utils.ByteArray; Import mx.events.RSLEvent; Import Mx.utils.LoaderUtil; [Excludeclass]/** * @private * RSL Item Class * * Contains properties to describe The RSL and methods to help load the RSL. */public class Rslitem {//--------------------------------------------------------------------------///// Properties////--------------------------------------------------------------------------//--------------------- -------------//URLRequest//----------------------------------/** * @private * Only valid after loading have started */ public Var urlrequest:urlrequest; ----------------------------------//Total//----------------------------------/** * @private */public var UINT = 0; ----------------------------------//Loaded//----------------------------------/** * @private */public var loaded: UINT = 0; ----------------------------------//Rooturl//----------------------------------/** * @private * * provides the URL u Sed to locate relative RSL URLs. */public Var rooturl:string; --------------------------------------------------------------------------////Variables////------------------ --------------------------------------------------------/** * @private */public var url:string; /** * @private * */private VAR errortext:string; /** * @private * */private var Completed:boolean = false; /** * @private * External handlers so the load can is * observed by the class calling load (). */protected Var chainedprogresshandler:function; protected Var chainedcompletehandler:function; protected Var chainedioerrorhandler:function; protected Var chainedsecurityerrorhandler:function; protected Var chainedrslerrorhandler:function; --------------------------------------------------------------------------////Constructor////---------------- ----------------------------------------------------------/** * Create a rslitem with a given URL. * * @param URL location in the RSL to load * * @param rooturl provides the URL used to locate relative RSL URLs. */Public Function Rslitem (url:string, rooturl:string = null) {super (); this.url = URL; this.rooturl = Rooturl;}//----- ---------------------------------------------------------------------////Methods////------------------------------------------------------------ --------------/** * * Load an RSL. * * @param progresshandler receives progressevent.progress events. * May is null. * * @param completehandler receives event.complete events. * May is null. * * @param ioerrorhandler receives ioerrorevent.io_error events. * May is null. * * @param Securityerrorhandler * receives Securityerrorevent.security_error events. * May is null. * * @param rslerrorhandler receives rslevent.rsl_error events. * May is null. */Public Function load (progresshandler:function, completehandler:function, Ioerrorhandler:function, Securityerrorhandler:function, rslerrorhandler:function): void {chainedprogresshandler = ProgressHandler; Chainedcompletehandler = Completehandler; Chainedioerrorhandler = Ioerrorhandler; Chainedsecurityerrorhandler = Securityerrorhandler; Chainedrslerrorhandler = Rslerrorhandler; var loader:loader = new Loader (); var loadercontext: Loadercontext = new Loadercontext (); URLRequest = new URLRequest (Loaderutil.createabsoluteurl (rooturl, url)); The Rslitem needs to listen to certain events. Loader.contentLoaderInfo.addEventListener (progressevent.progress, Itemprogresshandler); Loader.contentLoaderInfo.addEventListener (Event.complete, Itemcompletehandler); Loader.contentLoaderInfo.addEventListener (Ioerrorevent.io_error, Itemerrorhandler); Loader.contentLoaderInfo.addEventListener (Securityerrorevent.security_error, Itemerrorhandler); Loadercontext.applicationdomain = Applicationdomain.currentdomain; Loader.load (URLRequest, Loadercontext); }//--------------------------------------------------------------------------////Event Handlers////------------ --------------------------------------------------------------/** * @private */Public Function Itemprogresshandler ( Event:progressevent): void {//Update the loaded and total properties. loaded = event.bytesloaded; total = Event.bytestota L Notify an external Listener if (Chainedprogresshandler! = null) Chainedprogresshandler (event); }/** * @private */Public Function Itemcompletehandler (event:event): void {completed = true;//Notify an external listen ER if (chainedcompletehandler! = null) Chainedcompletehandler (event); }/** * @private */Public Function Itemerrorhandler (event:errorevent): void {errorText = decodeURI (event.text); completed = true; loaded = 0; Total = 0; Trace (ErrorText); Notify an external listener if (Event.type = = Ioerrorevent.io_error && Chainedioerrorhandler! = null) {chained Ioerrorhandler (event); } else if (Event.type = = Securityerrorevent.security_error && Chainedsecurityerrorhandler! = null) {Chainedsecur Ityerrorhandler (event); } else if (Event.type = = Rslevent.rsl_error && Chainedrslerrorhandler! = null) {Chainedrslerrorhandler (event);} } } }
Reference article Http://www.adobe.com/devnet/flex/articles/flex_performance/flex_performance.pdf