Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:08:00+00:00 2026-06-15T21:08:00+00:00

I am trying to parse an xml file and load Flex modules dynamically in

  • 0

I am trying to parse an xml file and load Flex modules dynamically in my application. But it loads only the last module everytime. I have a singleton class which does the parsing and loading of modules. Here is the class

package
{
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

import mx.controls.Alert;
import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;
import mx.modules.ModuleLoader;
import mx.modules.ModuleManager;

public class VappModuleManager
{

    private static var _instance:VappModuleManager;
    private static const MODULE_PATH:String="./com/emc/vapp/"; 
    private static const MANIFEST_PATH:String="module-manifest.xml";
    private var _module:IModuleInfo;
    private var _handler:Function;
    private var loader:URLLoader; 
    public function VappModuleManager(object:SingletonEnforcer)
    {

    }

    public function set handler(handler:Function):void
    {
        _handler=handler;
    }

    public static function get instance():VappModuleManager
    {
        if(_instance==null)
        {
            _instance=new VappModuleManager(new SingletonEnforcer());               
        }

        return _instance;
    }


    public function load():void
    {
        loader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, xmlLoaded);
        loader.load(new URLRequest(MANIFEST_PATH));
    }

    private function xmlLoaded(event:Event):void
    {
        Alert.show("Event Completed");
        var manifest:XML=new XML(event.target.data);
        Alert.show(manifest.module.length());

        for (var index:int=0;index<manifest.module.length();index++)
        {
            Alert.show(MODULE_PATH+manifest.module[index].@name);
            _module=ModuleManager.getModule(MODULE_PATH+manifest.module[index].@name);
            _module.addEventListener(ModuleEvent.READY,_handler);
            _module.load();
        }
    }


}
}
internal class SingletonEnforcer    {}

I use the above class as follows.

moduleManager=VappModuleManager.instance;

moduleManager.handler=myhandler;

moduleManager.load();

I understand the problem is with eventlistener for variable “_module” but dont know how to solve it. Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:08:01+00:00Added an answer on June 15, 2026 at 9:08 pm

    The call to IModuleInfo.load is asynchronous so your for loop has run completely before any of the modules have loaded. Also, your class level _module property is overwritten by a new Module instance each time the loop iterates.

    I’d suggest loading each module sequentially by waiting for the READY event and initiating the load of the next module only when it has fired. I’d also fire an event when all the modules are loaded instead of executing a callback function as this will give you more flexibility (multiple objects can listen for an event for example).

    The following isn’t tested, but should give you the idea:

    package
    {
        import flash.events.Event;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
    
        import mx.controls.Alert;
        import mx.events.ModuleEvent;
        import mx.modules.IModuleInfo;
        import mx.modules.ModuleLoader;
        import mx.modules.ModuleManager;
    
        public class VappModuleManager
        {
    
            private static var _instance:VappModuleManager;
    
            private static const MODULE_PATH:String="./com/emc/vapp/"; 
            private static const MANIFEST_PATH:String="module-manifest.xml";
    
            private var loader:URLLoader; 
            private var manifest:XML; 
            private var loadCount:int = 0; // track loaded modules
    
            public function VappModuleManager(object:SingletonEnforcer)
            {
    
            }
    
            public static function get instance():VappModuleManager
            {
                if(_instance==null)
                {
                    _instance=new VappModuleManager(new SingletonEnforcer());               
                }
    
                return _instance;
            }
    
    
            public function load():void
            {
                loader = new URLLoader();
                loader.addEventListener(Event.COMPLETE, xmlLoaded);
                loader.load(new URLRequest(MANIFEST_PATH));
            }
    
            private function xmlLoaded(event:Event):void
            {
                manifest =new XML(event.target.data);
    
                // load the first module
                loadModule();
            }
    
            private function loadModule() {
                // Use a locally scoped variable to avoid writing over the previous instance each time.
                // You could push these onto an array if you need to be able to access them later
                var module:IModuleInfo = ModuleManager.getModule(MODULE_PATH+manifest.module[loadCount].@name);
                module.addEventListener(ModuleEvent.READY, moduleReadyHandler);
                module.load();
            }
    
            private function moduleReadyHandler(event:ModuleEvent) {
                // Remove the event listener on the loaded module
                IModuleInfo(event.target).removeEventListener(ModuleEvent.READY, moduleReadyHandler);
    
                loadCount ++;
    
                // Are there still modules in the manifest to load?            
                if (loadCount < manifest.module.length()) {
                    // Yes... load the next module
                    loadModule();
                } else {
                    // No... we're all finished so dispatch an event to let subscribers know
                    dispatchEvent(new Event("complete"));
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse an XML file with python using lxml, but get
I'm trying to parse an XML file using PHP, but I get an error
I'm trying to parse a XML file, but when loading it simpleXML prints the
I'm trying to parse an xml file by starting with simplexml_load_file to load the
I am trying to parse Xml file using PHP but whenever i runs the
I am trying to parse specific XML file which is located in sub directories
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>
I'm trying to parse an xml file with PHP. I'm using this code and
I am trying to parse an XML file in java, after I have to
I am trying to parse an XML file into smaller XML files and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.