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 6563405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:49:39+00:00 2026-05-25T13:49:39+00:00

I am trying to call a method that has some xml functionality and It

  • 0

I am trying to call a method that has some xml functionality and It keeps coming up null. What I am trying to do is; I have a page that has four dynamic text fields that get their content from an xml file. I would like to create a method that will output the contents to display in the dynamic field. Maybe my approach is WAY off here, but my supervisor wants all xml related tasks contained in a xml.as file.

Main.as

package classes
{
    import flash.display.*;
    import flash.events.*;

    import classes.Xml; /* my custom class */

    public class Main extends MovieClip
    {
        public function Main():void
        {
            var xml:Xml = new Xml("menu.xml"); 
            trace(xml.getCourseTitle());
        }
    }
}

Xml.as

package classes
{
    import flash.display.*;
    import flash.net.*;
    import flash.events.*;

    public class Xml extends MovieClip
    {
        private var xml:XML;
        private var loader:URLLoader = new URLLoader();

        public function Xml(p:String):void
        {
            loader.load(new URLRequest(p));
            loader.addEventListener(Event.COMPLETE,processXML);   
        }
        public function processXML():void
        {
            xml = new XML(loader.data)
            trace(xml); /* this will trace all xml data in xml file */ 
        }
        public function getCourseTitle():String
        {
            return xml.@title; /* this is supossed to return Test Course */ 

        }       
    }
}

menu.xml

<?xml version="1.0"?>
    <course title="Test Course">
        <folder name="Question 1" link="1_1.swf"/>
   <folder name="Question 2" link="1_2.swf"/>
   <folder name="Question 3" link="1_3.swf"/>
   <folder name="Question 4" link="1_4.swf"/>
   <folder name="Question 5" link="1_5.swf"/>
   <folder name="Question 6" link="1_6.swf"/>
   <folder name="Question 7" link="1_7.swf"/>
   <folder name="Question 8" link="1_8.swf"/>
   <folder name="Question 9" link="1_9.swf"/>
   <folder name="Question 10" link="1_10.swf"/>
    </course>
  • 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-25T13:49:40+00:00Added an answer on May 25, 2026 at 1:49 pm

    Try this instead:

    Main.as(document class):

    package 
    {
        import com.example.CourseXML;
        import flash.display.Sprite;
        import flash.events.Event;
    
        public class Main extends Sprite 
        {
            public function Main():void 
            {
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE, init);
    
            }// end function
    
            private function init(e:Event = null):void 
            {
                removeEventListener(Event.ADDED_TO_STAGE, init);
    
                var courseXml:CourseXML = new CourseXML("xml/course.xml");
                courseXml.addEventListener(CourseXML.LOAD_COMPLETE, onCourseXmlLoadComplete);
                trace(courseXml.title)// output: null
    
            }// end function
    
            private function onCourseXmlLoadComplete(e:Event):void
            {
                var courseXml:CourseXML = CourseXML(e.target);
                trace(courseXml.title) // output: Test Course
    
            }// end function
    
        }// end class
    
    }// end package
    

    CouseXML.as:

    package com.example 
    {
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
    
        public class CourseXML extends EventDispatcher
        {
            public static const LOAD_COMPLETE:String = "loadComplete";
    
            private var _urlLoader:URLLoader;
            private var _xml:XML;
    
            public function get title():String 
            {
                var title:String;
    
                try 
                {
                    title = _xml.@title; 
                }
                catch (e:TypeError)
                {
                    title = null;
    
                }// end catch
    
                return title;
    
            }// end function
    
            public function CourseXML(url:String) 
            {
                _urlLoader = new URLLoader();
                _urlLoader.addEventListener(Event.COMPLETE, onUrlLoaderComplete);
                _urlLoader.load(new URLRequest(url));
    
            }// end function
    
            private function onUrlLoaderComplete(e:Event):void
            {
                _xml = XML(URLLoader(e.target).data);
    
                dispatchEvent(new Event(CourseXML.LOAD_COMPLETE));
    
            }// end function
    
        }// end class
    
    }// end package
    

    If your wondering about the try and catch in the CourseXML object’s title() getter method, I put that there so if you try and access any of the _xml property’s members before the xml file is loaded and assigned to it, you don’t get a nasty TypeError.

    [UPDATE]

    Upon second thought, the try and catch was unnecessary, it would have been easier to use a conditional statement like the following:

    public function get title():String 
    {
        return (_xml) ? _xml.@title : null;
    
    }// end function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that has got me very close to what Im trying
I have an interface that has ~16 input field boxes. They are all declared
I'm developing an app for Blackberry on OS 5. I'm trying to have some
As the title suggests, I am getting a FileNotFoundException when running a web page
I am using reflection and WSDL to call web services on the fly through
Okay, so I've done some looking around and I see how you are SUPPOSED
I'm new to this as I come from C++ and Perl background. Trying to
I am trying to find a solution to 'break into non-public methods'. I just
I'm trying to consume a Java based SOAP web service from VBA code in
I have a custom dialog (extends Dialog) whose contentview is a custom viewgroup. 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.