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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:43:46+00:00 2026-05-28T07:43:46+00:00

I have the requirement in a Flex application to create & populate an object

  • 0

I have the requirement in a Flex application to create & populate an object from the return from a call to a URL. Here is what I need to be able to do:

  1. I have a class which communicates with the web server.
  2. I have a function in this class (called getPerson) which would return a Person object which is populated from the XML data returned from the web server.

The problem I am running into (and it seems this is a very common problem, but I have not seen a solution which I can see would work) is that the load method of the URLLoader is asynchronous.

I have an event listener firing on the Event.COMPLETE event which parses the XML and populates my object in the event handler, but how would I get this object back to my originating code in my application which originally called my getPerson function?

So by the time the return from the server comes back, my method is finished and I cannot return my populated Person object.

My question is how can I accomplish this? I am still fairly new to ActionScript and have been spinning my wheels for a day now on this.

I’ve added some sample code which demonstrates the problem I am having – I have simplified what I am using:

MXML application file:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                             xmlns:s="library://ns.adobe.com/flex/spark" 
                             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                             creationComplete="application1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                var d:DAL = new DAL();
                d.CreateNewPerson( "John Smith" );
            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

</s:Application>

DAL.cs file:

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

  import mx.controls.Alert;

  public class DAL
  {
      public function DAL()
      {
      }

      public function CreateNewPerson( Name:String ):void
      {

          var strXML:String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
          var loader:URLLoader = new URLLoader();
          loader.addEventListener(Event.COMPLETE, onPostComplete);
          var request:URLRequest = new URLRequest( "http://www.cnn.com" );
          request.method = URLRequestMethod.POST;
          request.data = strXML;
          loader.load(request);
      }

      private function onPostComplete( evt:Event ):void
      {
          //Process returned string

          //Here is where I need to return my object
                  var obj:Object = new Object()
      }
  }
}

What I need to do is somehow get the “obj” variable back out to my MXML application file so I can use it there.

Thanks in advance!

  • 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-28T07:43:47+00:00Added an answer on May 28, 2026 at 7:43 am

    On your mxml application file:

    var d:DAL = new DAL();
    
    protected function application1_creationCompleteHandler(event:FlexEvent):void
    {
      d.CreateNewPerson( "John Smith" );
      d.addEventListener('PersonCreated', personCreated);
    }
    
    private function personCreated(evt:Event) :void
    {
      var obj:Object = new Object();
      obj = d.ojectToBeReturned;
      // obj will contain the object from your class...
    }
    

    On your DAL class, declare the object variable and create a getter/setter function, i.e.

    private var _myObjectToBeReturned:Object;
    
    public function get ojectToBeReturned() :Object
    {
      return _myObjectToBeReturned;
    }
    

    And on your method

    private function onPostComplete( evt:Event ):void
    {
      //Here is where I need to return my object
      _myObjectToBeReturned = new Object();
      // Perform the process for the object.
    
      // Call the event from your parent.  
      this.dispatchEvent(new Event('PersonCreated'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to be able to provide a flex component in English
I have requirement to get application cache object => session object, modify it and
I am new in C# and have requirement to retrieve a url from C#.
I have a requirement where users should be able to navigate from the first
I had developed the flex application with panel container. And I have a requirement
I have a requirement on my current project (a Flex app which will be
In our project we have requirement that, after receiving sms message from third party
I have a requirement to be be able to embed scanned tiff images into
i have requirement where i need to check if apex:inputCheckbox is checked, and if
I have requirement where I need to allow users to upload a Word document

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.