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

  • SEARCH
  • Home
  • 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 6841307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:57:01+00:00 2026-05-26T23:57:01+00:00

I have a Flash application that creates a sort of powerpoint presentation. All the

  • 0

I have a Flash application that creates a sort of powerpoint presentation.
All the ‘slides’ are stored in an XML files which is read and processed.

I’m trying to build the presentation using this XML file.

At the moment, my main class has it’s initial function main and a static function processXML
main initiates my database class with a function called initDB. One of my issues is that initDB forgoes processing because it’s dependant on an event listener. On completion of loading the XML files, the event listener initiates my static function on my main to create objects from this file.

The issue is that because the event listener continues the processing (after an indeterminate amount of time), the functions are no longer controlled by the main class.
Normally, in this situation, I’d avoid the use of statics because I’d control processing from the main function by using returns on processing – i.e. a function that returns a value to pull control back to the caller class.

Now, all this has had a knock on effect and I can’t use addChild calls, or indeed any similar calls because the function is static.

If you could spare some time, I really need to re-think the way my files work.

Main Class

public static var databaseXML:XML;
public var database:ContentDatabase = new ContentDatabase();

public function main()
{
    database.initDB();
}

public static function processXML()
{
    //Get First Slide
    var introSlide:SlideLayout = new SlideLayout();
    var allSlides:XMLList = main.databaseXML.children();
    var introSlideXML:XML;
    for each (var slide:XML in allSlides)
    {
        introSlideXML = slide;
        break;
    }
    var theSlide:MovieClip = introSlide.createSlide(introSlideXML);
    addChild(theSlide); //Fails, Obviously
}

ContentDatabase Class

private var xmlLoader:URLLoader;

public function initDB()
{
    xmlLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    xmlLoader.load(new URLRequest("resources/slides.xml"));
}

private function onComplete(e:Event):void
{
    try
    {
        main.databaseXML = new XML(e.target.data);
        xmlLoader.removeEventListener(Event.COMPLETE, onComplete);
        xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
        main.processXML();
    }
    catch (err:Error)
    {
        trace('broke: ' + err.message);
    }
}
private function onIOError(e:IOErrorEvent):void
{
    trace('broke: ' + e.text);
}

I’m open to all ideas about how I structure this project to allow me this kind of communication.

Ideally, I’d like the ContentDatabase class to hold nothing but XML processing.

  • 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-05-26T23:57:01+00:00Added an answer on May 26, 2026 at 11:57 pm

    Your Main & ContentDatabase classes are too tied up!

    Your data is contained in an XML file, practically you need to first load the file, parse , organize & store the data, then you can manipulate this data.

    I disagree with Sr.Richie, a Singleton is really not needed here.

    ContentDatabase should simply care about loading the XML , ideally the source url shouldn’t be hardcoded in the class.

    For instance , you could pass the url as a parameter to the initDb method

         database.initDB("resources/slides.xml");
    

    After the data has been loaded, good practice would be to dispatch an event to inform the Main class that the data is ready. You could use a CustomEvent or use a Signal and pass the data as an Object. In this way you wouldn’t have unnecessary dependencies between the Main and the ContentDatabase classes.

        private function onComplete(e:Event):void
        {
            try
            {
                main.databaseXML = new XML(e.target.data);
                xmlLoader.removeEventListener(Event.COMPLETE, onComplete);
                xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
    
                //better process the XML data here...
                processXML();
    
            }
            catch (err:Error)
            {
                trace('broke: ' + err.message);
            }
        }
    
        private function processXML():void
        {
             // process the data...
             // inform the Main class by dispatching an Event
             // and pass the data as a parameter
             // use a CustomEvent or a Signal
         }
    

    Then in your Main class

         //If you use a CustomEvent
         private function xmlLoadComplete( event:XMLCustomEvent ):void
         {
             var introSlideXML:XML = event.introSlideXML;
             var theSlide:MovieClip = introSlide.createSlide(introSlideXML);  
         }
    

    There are several ways to dispatch & listen to Events between the Main class & the ContentDatabase. As mentioned above , you could use Signals. You could also create a light dependency by passing an event dispatcher to the ContentDatabase. You do that to ensure that the same dispatcher listens to and dispatches event.

         public var database:ContentDatabase = new ContentDatabase(dispatcher);
    

    Then in the ContentDatabase contstructor…

           this.dispatcher = dispatcher;
    

    then in processXML()

        private function processXML():void
        {
              // after all the processing
              dispatcher.dispatchEvent( new XMLCustomEvent (introSlideXML ) );
         }
    

    And of course in your Main class

       //In case of CustomEvent
       public function main()
       {
           //the same dispatcher listens
           dispatcher.addEventListener( XMLCustomEvent.XML_LOADED , 
                                            xmlLoadComplete );
           database.initDB();
       }
    

    Although it is possible to use an XML as a native AS3 object, I often prefer to create my own Object or Class, populate it with the XML data so that I can call its properties directly , instead of having to query the XML , but that’s personal taste…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flex 3 application that creates an Image from a canvas which
I have application which consumes XML and based on this creates a GUI. Basically
I have a Flash AS2 application that is made up of many SWF files.
I have a Flash application that is hosted from within a Drupal page. Some
I have an projector file/Flash application that I need to turn into an interactive
we have a small flash component on our website/application to upload multiple files. This
I have a FLASH object that I mouse over which in turn calls the
I have a very simple console application that creates a text file. Below is
I currently have an application that calls creates and displays charts from various objects'
I have a flex application that loads swf files and displays them using the

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.