as3 TypeError#2007参数文本必须为非null无法修复

时间:2014-02-20 19:52:58

标签: php actionscript-3 actionscript

我有评论框项目。基于As3 + php的项目。并且有#2007 Error.Try修复但无法做任何事情。如果可以帮助它会非常有帮助。错误的部分是这样的:

TypeError:错误#2007:参数文本必须为非null。     在flash.text :: TextField / set text()     在comment2_fla :: mc_1 / completeHandler()     在flash.events::EventDispatcher/dispatchEventFunction()     at flash.events::EventDispatcher/dispatchEvent()     在flash.net::URLLoader/onComplete()

var variables_re:URLVariables = new URLVariables();
var varSend_re:URLRequest = new URLRequest("guestbookParse.php");
varSend_re.method = URLRequestMethod.POST;
varSend_re.data = variables_re;

var varLoader_re:URLLoader = new URLLoader;
varLoader_re.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader_re.addEventListener(Event.COMPLETE,completeHandler_re);

function completeHandler_re(event:Event):void{
    if(event.target.data.returnBody==""){
       gbOutput_txt.text = "no data";
       } else {
           gbOutput_txt.condenseWhite = true;
           gbOutput_txt.htmlText = "" + event.target.data.returnBody;

       }
}

variables_re.comType = "requestEntries";
varLoader_re.load(varSend_re);

代码的第二部分:

msg_txt.restrict = "ığüşöç A-Za-z 0-9";
name_txt.restrict = "ığüşöç A-Za-z 0-9";

var errorsFormat:TextFormat = new TextFormat();
errorsFormat.color = 0XFF0000;
processing_mc.visible = false;

var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("guestbookParse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE,completeHandler);

function completeHandler(event:Event):void{ 
    processing_mc.visible = false;
    name_txt.text = "";
    msg_txt.text = "";
    status_txt.text = event.target.data.return_msg;
    gbOutput_txt.condenseWhite = true;
    gbOutput_txt.htmlText=""+event.target.data.returnBody;



}

submit_btn.addEventListener(MouseEvent.CLICK,ValidateAndSend);

function ValidateAndSend(event:MouseEvent):void{

    if(!name_txt.length){
        status_txt.text = "İsminizi Girin";
        status_txt.setTextFormat(errorsFormat);
    } else if (!msg_txt.length){
        status_txt.text = "Yorum Girin";
        status_txt.setTextFormat(errorsFormat);
    }else{
        processing_mc.visible = true;

        variables.comType = "parseComment";
        variables.userName = name_txt.text;
        variables.userMsg = msg_txt.text;

        varLoader.load(varSend);
        status_txt.text = "Yorumunuz Eklendi...";
    }
}

和php部分:

<?php

mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("yorum") or die (mysql_error());

if ($_POST['comType'] == "parseComment") {

    $name = $_POST['userName'];
    $location = $_POST['userLocation'];
    $comment = $_POST['userMsg'];

    $sql = mysql_query("INSERT INTO guestbook (name, post_date, comment, location) 
        VALUES('$name', now(),'$comment','$location')")  
        or die (mysql_error());

    $body = "";
    $sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC"); 
    while($row = mysql_fetch_array($sql)) {
        $id = $row["id"];
        $name = $row["name"];
        $post_date = $row["post_date"];
        $comment = $row["comment"];
        $location = $row["location"];

        $comment = stripslashes($comment);
        $name = eregi_replace("&#39;", "'",  $name);
        $location = eregi_replace("&#39;", "'",  $location);
        $comment = eregi_replace("&#39;", "'", $comment);

        $post_date = strftime("%b %d, %y", strtotime($post_date));

        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <font color="#9B9B9B">' . $location . '</font>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
        <br />
        '.$comment.'
        <br />
        <br />
        ';
    }
    mysql_free_result($sql);
    mysql_close();


     echo "return_msg=Entry has been added successfully $name, thanks!&returnBody=$body";
     exit();

} 

if ($_POST['comType'] == "requestEntries") {

    $body = "";
    $sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC"); 
    while($row = mysql_fetch_array($sql)) { 
        $id = $row["id"];
        $name = $row["name"];
        $post_date = $row["post_date"];
        $comment = $row["comment"];
        $location = $row["location"];
        $comment = stripslashes($comment);

        $post_date = strftime("%b %d, %y", strtotime($post_date));

        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <font color="#9B9B9B">' . $location . '</font>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
        <br />
        '.$comment.'
        <br />
        <br />
        ';
    }
    mysql_free_result($sql);
    mysql_close();
    echo "returnBody=$body";
    exit();
} 
?>

1 个答案:

答案 0 :(得分:0)

错误意味着您尝试执行类似

的操作
textInput.text=null; 

我认为这是问题所在

status_txt.text = event.target.data.return_msg;

首先尝试检查您为text属性设置的值是否为null或未定义。

要修复你可以做到

status_txt.text = event.target.data.return_msg?event.target.data.return_msg :""

var message:String= event.target.data.return_msg;
if(!message) message="";
 status_txt.text =message;

编辑2: 试试这个

var message:String=event.target.data;
status_txt.text =message;

如果为空或者预期结果显示您要显示的内容,则必须解析此消息字符串。