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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:45:00+00:00 2026-06-09T11:45:00+00:00

I’m trying to access the data_file value in the onComplete function, but to be

  • 0

I’m trying to access the data_file value in the onComplete function, but to be honest I’m not even sure I’m calling it correctly.

public function version():String{
    var string_val = "";
    var data_file = "";

    //var request:URLRequest = new URLRequest("indexdynamic.php");
    var request:URLRequest = new URLRequest("http://localhost/indexdynamic.php");
        request.method = URLRequestMethod.POST;

    var verVars:URLVariables = new URLVariables();

    request.data = verVars

    var loader:URLLoader = new URLLoader(request);
    loader.addEventListener(Event.COMPLETE, onComplete);
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.load(request);

    function onComplete(event:Event):String{
        string_val = event.target.data.Var.toString();

        if (string_val ==  "First Selection") {
            data_file = "fill_in_blanks_doi.xml";
        }else {
            data_file = "fill_in_blanks_2_doi.xml";
        }
        return data_file;
    }
    var data_file = onComplete(loader.COMPLETE);
    return data_file;
}
  • 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-09T11:45:02+00:00Added an answer on June 9, 2026 at 11:45 am

    Typically Event Listener functions return void. So you don’t get the value from an event listener through the return value.

    So step one:

    Remove: var data_file = onComplete(loader.COMPLETE);
    Remove: return data_file; // Remove Both lines. that return a value.
    Change the function header to return void:

    function onComplete(event:Event):void{
    

    Now you will have saved your “data_file” variable, and not overwritten it by accident. However, since this is an asynchronous operation, some part of your code is now waiting to be called now that you have the variable set. You need to add one more line inside onComplete() to continue execution of code in your app. It might be something like:

    processXML(data_file);
    

    or

    trace("Data File:", data_file);
    

    Hope that clears it up for you.

    === Edit ===

    I went back and read your code again, and I notice something else. You are declaring a function within a function. That’s usually not such a great idea. I recommend moving your onComplete() function outside of the getVersion() function.

    Second – your getVersion() function returns a string, meaning it is a synchronous function – meainign the calling code expects an answer back instantly. This will not work. URLLoader is asynchronous – you call it, and at some indeterminitate point in the future it responds. So your code is free to do other stuff – like display a loader bar – while it gets a response form the server andthe data is transferred. When it is done, the laoder will call its listeners. Only at this point will your original goal of describing the version be possible.

    So – you will need to change your code to pause its execution until the load completes, then have the onComplete listener start the ball rolling again once the information is loaded and ready to be used.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.