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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:33:59+00:00 2026-05-24T02:33:59+00:00

I am noob in Flex/Actionscript so I have the code where compiler doesn’t show

  • 0

I am noob in Flex/Actionscript so I have the code where compiler doesn’t show error but code returns nothing. Can you help me to fix it?

Main.mxml

<?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="main()">
    <fx:Script>
        <![CDATA[
            include 'AS/main.as';

            private function main():void {
                Label1.text = Login('irakli','password1');
            }

        ]]>
    </fx:Script>
    <s:Label id="Label1" x="370" y="176" text="Label"/>
</s:Application>

main.as

// ActionScript file
import flash.events.*;
import flash.net.*;

var Answer:String;

function Login(username:String, password:String){
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest('http://localhost/hosting/index.php');

    request.method = URLRequestMethod.POST;
    var variables:URLVariables = new URLVariables();
    variables.username = username;
    variables.password = password;
    request.data = variables;

    //handlers
    loader.addEventListener(Event.COMPLETE, function(e:Event):void{
        var loader:URLLoader = URLLoader(e.target);
        Answer = loader.data;
    });
    loader.load(request);

    var i:int = 1;
    while (i < 10000000000){
        if (Answer.length > 0){
            return Answer; 
            break;
        }
        i++;
    }
}

I know about that it is good to use event handler functions, but I want that this code worked in main.mxml Label1.text = Login('irakli','password1');

  • 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-24T02:34:00+00:00Added an answer on May 24, 2026 at 2:34 am

    Sorry, but wanting this to work in this fashion is simply wrong. You have no guarantee that that absurd loop will work because it could easily complete before your load operation does. Also, having a function inline in your event handler is considered bad practice.

    The correct approach to this would be to make Login a class, and listener for an event coming out of it in order to populate the text box.

    This is how you could write Login as a class:

    package {
        import flash.events.*;
        import flash.net.*;
    
        public class Login extends EventDispatcher
        {
            public function Login(username:String, password:String):void
            {
                var loader:URLLoader = new URLLoader();
                var request:URLRequest = new URLRequest('http://localhost/hosting/index.php');
                request.method = URLRequestMethod.POST;
                var variables:URLVariables = new URLVariables();
                variables.username = username;
                variables.password = password;
                request.data = variables;
    
                loader.addEventListener(Event.COMPLETE, loadCompleteHandler);
                loader.load(request);
            }
    
            private function loadCompleteHander(evt:Event):void
            {
                // set the event on out of the class
                dispatchEvent(evt);
            }
        }
    }
    

    So then you would use this like this:

    var login:Login = new Login('irakli','password1');
    login.addEventListener(Event.COMPLETE,setTheText);
    
    function setTheText(evt:Event):void
    {
        Label1.text = evt.target.data;
    }
    

    Of course if you don’t want listeners in your mxml (and I can’t understand why that would be), then I think your best approach would be to pass the target textField into your Login function and let it set the text in the inline handler. Something like:

    Login('irakli','password1',Label1);
    

    main.as

    // ActionScript file
    import flash.events.*;
    import flash.net.*;
    import flash.text.TextField
    
    var targetTF:TextField;
    
    function Login(username:String, password:String,textField:TextField){
        targetTF = textField;
        var loader:URLLoader = new URLLoader();
        var request:URLRequest = new URLRequest('http://localhost/hosting/index.php');
    
        request.method = URLRequestMethod.POST;
        var variables:URLVariables = new URLVariables();
        variables.username = username;
        variables.password = password;
        request.data = variables;
    
        //handlers
        loader.addEventListener(Event.COMPLETE, function(e:Event):void{
            var loader:URLLoader = URLLoader(e.target);
            targetTF.text = loader.data;
        });
        loader.load(request);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please enlighten this flex noob. I have a remoteobject within my main.mxml. I can
I'm a complete Flex/Flash noob, running Adobe Flash Builder 4 Beta 2. I have
I am a complete noob to c. I have downloaded a code from internet.
I am a complete noob to android but I have been programing c# for
This might be a noob question, but I need help. I screwed up my
Noob question. I have been programming at basic level for quite a while but
Noob Question I know but can you explain to me how I can install
I'm a complete Flex noob, so I apologize in advance if I'm missing something
I am a noob when it comes to python. I have a python script
I know this may be a noob question, but it's bugging the heck out

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.