AS3动态数据加载错误

时间:2015-11-25 02:23:35

标签: php mysql actionscript-3 flash

我使用PHP MySQL和AS3根据站点编号加载动态数据。当我点击下一个网站时出现问题,它会向现有网站添加一个增量并显示新网站,但出于某种原因,不会从旧网站中删除内容?

我的PHP

$dbHost = "localhost";
$dbUser = "username";
$dbPass = "password";
$dbName = "dbname";
$dbTable = "tablename";

if (isset($_GET['sn'])) {
$sn = $_GET['sn'];
}

// connecting and selecting database
@mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
@mysql_select_db($dbName) or die(mysql_error());

// getting data
  $data = "";
  $datatitle = "";
  $res = mysql_query("SELECT * FROM ".$dbTable." WHERE Site_ID='$sn'") or die(mysql_error());
  while($row = mysql_fetch_object($res)) {
    $data .= strip_tags($row->Site_Description);
}
die($data);

我的AS3包裹代码:

package {

import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.text.TextField;
import flash.events.IOErrorEvent;

public class App extends MovieClip {
    public static const URL:String = 'weburl/get.php';
    private var loader:URLLoader;
    private var request:URLRequest;
    public function App():void {
        output(" ");
        loadData();
    }

    var siteNumber = 2;     

    public function loadData():void {

        var randomParam:String = "?p=" + Math.floor(Math.random() * (10000000)) + "&sn=";
        this.loader = new URLLoader();
        request = new URLRequest(URL + randomParam + siteNumber);
        request.method = URLRequestMethod.POST;
        loader.addEventListener(Event.COMPLETE, onLoadData);
        loader.addEventListener(IOErrorEvent.IO_ERROR, onDataFiledToLoad);
        loader.addEventListener(IOErrorEvent.NETWORK_ERROR, onDataFiledToLoad);
        loader.addEventListener(IOErrorEvent.VERIFY_ERROR, onDataFiledToLoad);
        loader.addEventListener(IOErrorEvent.DISK_ERROR, onDataFiledToLoad);
        loader.load(request);

        } 

    public function onLoadData(e:Event):void {
        output( e.target.data);
    }
    private function onDataFiledToLoad(e:IOErrorEvent):void {
        output("onDataFiledToLoad error=" + e.text);
    }

    public function output(str:String):void {
        var text:String = field.htmlText;
        field.htmlText = str + text;

    }

    function removeExisting():void {

            this.loader.close();
    }

  }


}

我在框架上使用的代码

next_site1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlernext_site1); 
            function mouseDownHandlernext_site1(event:MouseEvent):void 
            { siteNumber = siteNumber + 1;

                SiteNumberText1.text = siteNumber.toString();
                loadData();
            }
prev_site1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerprev_site1); 
            function mouseDownHandlerprev_site1(event:MouseEvent):void 
            { siteNumber = siteNumber - 1;

                SiteNumberText1.text = siteNumber.toString();
                loadData();

            }

我知道您必须卸载数据,但似乎无法找到有效的解决方案。

我已经在下面查看了这些问题,但是他们确实提供了帮助(没有提到如何卸载数据或新数据没有替换旧数据的原因。):

xml data to dynamic text AS3 flash

AS3 Save & Load multiple text boxs data to local file(s)

1 个答案:

答案 0 :(得分:0)

正如其他人所说,你保留旧的输出并添加新的输出,而不是用新的替换旧的输出。这是field.htmlText = str + text;行。 相反,用给定的(新)内容覆盖你的htmlText。

public function output(str:String):void {
    field.htmlText = str;
}