# Functions aren't working

**URL:** <https://forum.kirupa.com/t/functions-arent-working/291180>\
**Category:** flash\
**Created:** [June 25, 2009, 8:42pm UTC](https://forum.kirupa.com/t/functions-arent-working/291180 "2009-06-25T20:42:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankyboy](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@frankyboy](https://forum.kirupa.com/u/frankyboy)\
**Post date:** [June 25, 2009, 8:42pm UTC](https://forum.kirupa.com/t/functions-arent-working/291180/1 "2009-06-25T20:42:28Z")

</div>

I have one function that for some reason, isn’t calling the next function. I’ve been looking over this code all day and I feel like it’s probably going to be something really small and stupid but I jsut really need help at this point. The function that isn’t working is showUsers().  
This is my code:

```auto
import fl.controls.*;
import flash.display.Sprite;
import fl.managers.StyleManager;

/ ************************************************************ /
/ ************************DECLARATIONS********************** /
/ ************************************************************ /
var backgroundArea:Sprite = new Sprite();
var loginArea:Sprite = new Sprite();
var userArea:Sprite = new Sprite();

var userText:Label = new Label();
var userInput:TextInput = new TextInput();

var passText:Label = new Label();
var passInput:TextInput = new TextInput();

var loginButton:Button = new Button();

var userList:List = new List();

var loginFormat:TextFormat = new TextFormat();

/ ************************************************************ /
/ **************************METHODS************************* /
/ ************************************************************ /
function login(evt:MouseEvent):void
{
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, dataOnLoad);

    var variables:URLVariables = new URLVariables();
    variables.UserName = userInput.text;
    variables.Password = passInput.text;

    var myData:URLRequest = new URLRequest("./php/login.php");
    myData.data = variables;
    myData.method = URLRequestMethod.POST;

    loader.load(myData);
}

function dataOnLoad(evt:Event):void
{
    var string:String = "";
    string = evt.target.data.result;

    if (string == "yes")
    {
        backgroundArea.removeChild(loginArea);
        showUsers();
    }
}

function showUsers():void // This one right here. The backgroundArea.addChild(userArea) works but then the loader never seems to complete and so the userOnLoad function never gets called.
{
    var loader2:URLLoader = new URLLoader();
    loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader2.addEventListener(Event.COMPLETE, userOnLoad);

    var myData2:URLRequest = new URLRequest("./php/fillUserList.php");
    myData2.method = URLRequestMethod.POST;
    
    loader2.load(myData2);
    backgroundArea.addChild(userArea);
}

function userOnLoad(evt:Event):void
{
    var string:String = "";
    var i:int = 0;
    
    userList.addItem({label:"Gordon3", age:"very old", data:123});
    userArea.addChild(userList);

    /*while(string != null)
    {
    string = evt.target.data.user + i;
    
    userList.addItem(string);
    
    i++;
    }*/
}

/ ************************************************************ /
/ **********************MAIN CODE SECTION******************* /
/ ************************************************************ /

// Create the main background
backgroundArea.graphics.beginFill(0xbbbbbb);
backgroundArea.graphics.drawRect(0,0,550,400);
backgroundArea.graphics.endFill();
addChild(backgroundArea);

// Create the main login square
loginArea.graphics.beginFill(0x52ADE9);
loginArea.graphics.drawRect(100,50,350,300);
loginArea.graphics.endFill();
backgroundArea.addChild(loginArea);

// Format the text on the page
loginFormat.font = "Verdana, Arial, sans-serif";
loginFormat.bold = true;
loginFormat.size = 12;
StyleManager.setStyle("textFormat", loginFormat);

// Create the username text and input box
userText.text = "UserName:";
userText.x = 175;
userText.y = 100;
loginArea.addChild(userText);

userInput.x = 275;
userInput.y = 100;
loginArea.addChild(userInput);

// Create the password text and input box
passText.text = "Password:";
passText.x = 175;
passText.y = 175;
loginArea.addChild(passText);

passInput.x = 275;
passInput.y = 175;
loginArea.addChild(passInput);

// Create the login button
loginButton.label = "Login";
loginButton.x = 225;
loginButton.y = 250;
loginArea.addChild(loginButton);

// Listen for the button click
loginButton.addEventListener(MouseEvent.CLICK, login);

// Create the userArea
userArea.graphics.beginFill(0x48C6FB);
userArea.graphics.drawRect(100,50,350,300);
userArea.graphics.endFill();

// Create the userList
userList.x = 225;
userList.y = 100;

```
