2014-02-20 77 views
0

我有評論框項目。基於As3 + PHP的項目。並有#2007 Error.Try修復,但不能做任何事情。如果可以幫助它將是非常有用的。錯誤部分是這樣的:as3 TypeError#2007參數文本必須爲非空不能修復

TypeError:Error#2007:Parameter text must be非空。 在的flash.text ::文本字段/設置文本() 在comment2_fla :: mc_1 /在completeHandler() 在flash.events::EventDispatcher/dispatchEventFunction() 在flash.events::EventDispatcher/dispatchEvent() 在閃光達網絡::的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(); 
} 
?> 
+0

我添加了一些可能的修復,你只需要使用默認值,如果消息是nll或undefined – simion314

回答

0

的錯誤意味着你試圖做類似

textInput.text=null; 

我覺得這是有問題的線

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

首先嚐試檢查您是否設置該值文本屬性不爲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; 

你將不得不解析這個消息字符串,如果是空的或如果預期結果並顯示你想要顯示的內容。

+0

我想我有關於PHP部分的問題。因爲我無法添加數據到database.when .swf工作我可以輸入文本到文本字段,但我看到php代碼部分在評論pannel並且看不到任何輸入評論。 – posetcayiii

+0

這可能是,我認爲我的答案解決了最初的問題。關於調試你的PHP的建議,首先從瀏覽器測試你的PHP代碼(使用GET也許如果很容易,那麼當所有工作變回POST),並試圖在退出php腳本之前回顯任何mysql錯誤。測試小零件很容易,並回顯狀態消息,以便知道執行的是什麼。希望這可以幫助。 – simion314

+0

我不知道PHP編碼,但我會嘗試修復.Thx求助 – posetcayiii

相關問題