开发者

Flex ModuleManager unload module

I use ModuleManager load a module, like this Class:

 public class LoadModule
    {
   开发者_Go百科     private static var info:IModuleInfo;
        private static var display:IVisualElement;
        private static var downloadBar:ProgressBar;
        private static var parent:Group;


        public function LoadModule()
        {

        }
        //load module
        public static function load(url:String, parent:Group, bar:Boolean = true):void {
            LoadModule.parent = parent;
            info = ModuleManager.getModule(url);
            info.addEventListener(ModuleEvent.READY, readyHandler);
            info.addEventListener(ModuleEvent.SETUP, setupHandler);
            info.addEventListener(ModuleEvent.ERROR, errorHandler);
            info.load(null, null, null, parent.moduleFactory);

        }

        //add display object
        private static function readyHandler(event:ModuleEvent):void {
            LoadModule.display = event.currentTarget.factory.create() as IVisualElement;
            parent.addElement(LoadModule.display);
        }

        private static function setupHandler(event:ModuleEvent):void {

        }
        //unload module
        public static function unload():void {
            if (LoadModule.info != null) {
                LoadModule.info.addEventListener(ModuleEvent.UNLOAD, unloadHandler);
                LoadModule.info.unload();
                if (parent.getElementIndex(LoadModule.display) != -1) {
                    parent.removeAllElements();
                    LoadModule.display = null;
                }
            }
        }

        private static function unloadHandler(event:ModuleEvent):void {
            LoadModule.info.removeEventListener(ModuleEvent.UNLOAD,unloadHandler);
            trace("unloadModue");
        }
        //
        private static function progresshandler(event:ModuleEvent):void {
            downloadBar.label = "haved" + Math.round((event.bytesLoaded /event.bytesTotal) * 100) + "%";
        }

        private static function errorHandler(event:ModuleEvent):void {
            throw Error(event.errorText);
        }

        public static function setDownloadbar(downloadBar:ProgressBar):void {
            LoadModule.downloadBar = downloadBar;
        }
    }

Then i load a module and unload a module:

 LoadModule.unload(); // 1
   LodModule.load('..one.swf', parent);
   LoadModule.unload(); //2
   LodModule.load('...one.swf', parent);

In theory, It's only one module in my application, and I use "PopUpManager" pop a box, it shoud be one box. But, in fact, It's pop tow box. I use Flash builder debug this code, and It does not notice me unloade swf.. I guess, It has tow module in appliction. So, I need help. How to unload module in ModuleManager. I wish one module in application , not tow. Thanks.


If I understand the question correctly, it sounds like you are having trouble unloading your module. There's a great Adobe resource that can help you solve these issues. A few considerations:

"If you have a module that does not unload, the steps to diagnose the problem are: 1) Make sure the module is being loaded into a child applicationDomain (use default parameters for the load() method in most cases) 2) Use the profiler to make sure there are no references to objects in the module."

If you reference any objects in the module, the module will not unload. You will want to check that the following areas make no reference to the module in question:

  1. Styles
  2. Resources
  3. ExternalInterface.addCallback functions
  4. Timers and Timer mechanisms
  5. Listeners
  6. Focus
  7. Remote Objects
  8. Loaded images
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜