Skip navigation
Currently Being Moderated

Voting poll using PHP & MySQL >>TypeError: Error #2007: Parameter text must be non-null.

Dec 12, 2010 11:17 PM

I am getting this back:



TypeError: Error #2007: Parameter text must be non-null.

at flash.text::TextField/set text()

at AS3_Flash_Poll_PHP_MySQL_fla::WholePoll_1/completeHandler()






PHP code:




// ---------------------------------------- Section 1 -----------------------------------------------

//  IMPORTANT!!!! Connect to MySQL database here(put your connection data here)

mysql_connect("","fall2010","@regina") or die (mysql_error());

mysql_select_db("poll_2010") or die (mysql_error());


// When Flash requests the totals initially we run this code

if ($_POST['myRequest'] == "load_numbers") {


// Query the totals from the database

    $sql1 = mysql_query("SELECT id FROM votingPoll WHERE choice='1'");

    $choice1Count = mysql_num_rows($sql1);

    $sql2 = mysql_query("SELECT id FROM votingPoll WHERE choice='2'");

    $choice2Count = mysql_num_rows($sql2);

    $sql3 = mysql_query("SELECT id FROM votingPoll WHERE choice='3'");

    $choice3Count = mysql_num_rows($sql3);


    echo "choice1Count=$choice1Count";

    echo "&choice2Count=$choice2Count";

    echo "&choice3Count=$choice3Count";



// ---------------------------------------- Section 2 -----------------------------------------------


if ($_POST['myRequest'] == "store_choice") {


    //Obtain user IP address

    $ip = $_SERVER['REMOTE_ADDR'];

    // Create local variable from the Flash ActionScript posted variable

    $userChoice = $_POST['userChoice'];

    $sql = mysql_query("SELECT id FROM votingPoll WHERE ipaddress='$ip'");

    $rowCount = mysql_num_rows($sql);

    if ($rowCount == 1) {


$my_msg = "You have already voted in this poll.";

print "return_msg=$my_msg";


    } else {


$sql_insert = mysql_query("INSERT INTO votingPoll (choice, ipaddress) VALUES('$userChoice','$ip')")  or die (mysql_error());

$sql1 = mysql_query("SELECT * FROM votingPoll WHERE choice='1'");

$choice1Count = mysql_num_rows($sql1);

$sql2 = mysql_query("SELECT * FROM votingPoll WHERE choice='2'");

$choice2Count = mysql_num_rows($sql2);

$sql3 = mysql_query("SELECT * FROM votingPoll WHERE choice='3'");

$choice3Count = mysql_num_rows($sql3);

$my_msg = "Thanks for voting!";

        echo "return_msg=$my_msg";

        echo "&choice1Count=$choice1Count";

echo "&choice2Count=$choice2Count";

echo "&choice3Count=$choice3Count";






AS3 code:



stop(); // Stop the timeline since it does not need to travel for this to run


// Assign a variable name for our URLVariables object

var variables1:URLVariables = new URLVariables();


//  Build the varSend variable

var varSend1:URLRequest = new URLRequest("parse_my_poll.php");

varSend1.method = URLRequestMethod.POST; = variables1;


// Build the varLoader variable

var varLoader1:URLLoader = new URLLoader;

varLoader1.dataFormat = URLLoaderDataFormat.VARIABLES;

varLoader1.addEventListener(Event.COMPLETE, completeHandler1);


// Set variable to send to PHP here for the varloader below

variables1.myRequest = "load_numbers";  


// Send data to php file now, and wait for response using the COMPLETE event



function completeHandler1(event:Event):void{

    count1_txt.text = "" +;

    count2_txt.text = "" +;

    count3_txt.text = "" +;



// hide the little processing movieclip

processing_mc.visible = false;


// Initialize the choiceNum variable that we will use below

var choiceNum:Number = 0;


// Set text formatting colors for errors and success messages

var errorsFormat:TextFormat = new TextFormat();

errorsFormat.color = 0xFF0000; // bright red


var successFormat:TextFormat = new TextFormat();

successFormat.color = 0x00FF00; // bright green



// Button Click Functions

function btn1Click(event:MouseEvent):void{

    choiceNum = 1;

    choice_txt.text = choice1_txt.text;


function btn2Click(event:MouseEvent):void{

    choiceNum = 2;

    choice_txt.text = choice2_txt.text;


function btn3Click(event:MouseEvent):void{

    choiceNum = 3;

    choice_txt.text = choice3_txt.text;


// Button Click Listeners

btn1.addEventListener(MouseEvent.CLICK, btn1Click);

btn2.addEventListener(MouseEvent.CLICK, btn2Click);

btn3.addEventListener(MouseEvent.CLICK, btn3Click);



// Assign a variable name for our URLVariables object

var variables:URLVariables = new URLVariables();


//  Build the varSend variable

var varSend:URLRequest = new URLRequest("parse_my_poll.php");

varSend.method = URLRequestMethod.POST; = variables;


// Build the varLoader variable

var varLoader:URLLoader = new URLLoader;

varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

varLoader.addEventListener(Event.COMPLETE, completeHandler);


// Handler for PHP script completion and return

function completeHandler(event:Event):void{

    // remove processing movieclip

    processing_mc.visible = false;

    // Clear the form fields

    choice_txt.text = "";

    choiceNum = 0;

    // Load the response from the PHP file

    status_txt.text =;


    if ( == "Thanks for voting!") {

        // Reload new values into the count texts only if we get a proper response and new values


        count1_txt.text = "" +;

        count2_txt.text = "" +;

        count3_txt.text = "" +;



// Add an event listener for the submit button and what function to run

vote_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);


// Validate form fields and send the variables when submit button is clicked

function ValidateAndSend(event:MouseEvent):void {

    //validate form fields

    if(!choice_txt.length) {  

        // if they forgot to choose before pressing the vote button

        status_txt.text = "Please choose before you press vote.";  



    } else {

        status_txt.text = "Sending...";

        processing_mc.visible = true;

        // Ready the variables for sending

        variables.userChoice = choiceNum;

        variables.myRequest = "store_choice";  

        // Send the data to the php file


    } // close else after form validation


} // Close ValidateAndSend function ////////////////////////

  • Currently Being Moderated
    Dec 13, 2010 2:09 AM   in reply to regina2005

    This error means that you are trying to set the text field but there is no data in the variable. As a first step, try to identify where this is happening, eg Is it the first call, or once you have submitted your data or only if you try to submit data second time?


    Trace out the data that is returned for both completeHandlers to see if there is a missing var. Try this for "load_numbers" and "store_choice". Do it twice for "store_choice". Do you get back what you expected?


    You could also try altering the php to return some fixed dummy variables, eg  choice1Count=11&choice2Count=22&choice3Count=33, etc. If this works then you know that the error is in the PHP.


    It looks to me like the issue is when you submit the data a second time and just get back the return_msg - the handler then tries to assign the choice1Count etc but doesn't have any count data back from the poll.php.


    Test that there is data before assigning it, eg


            count1_txt.text =;
            count2_txt.text =;
            count3_txt.text =;

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points