php - AS3 dynamic data loading incorrectly


I am using PHP MySQL and AS3 to load dynamic data depending on the site number. The problem when i click next site, it adds an increment to the existing site and displays the new site, but for some reason doesn't remove the content from the old site?


$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);

my AS3 package code:

package {

import flash.display.MovieClip;
import flash.display.Loader;
import flash.text.TextField;

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(" ");

    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);


    public function onLoadData(e:Event):void {
    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 {




The code I am using on the frame

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

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

                SiteNumberText1.text = siteNumber.toString();


I understand that you have to unload the data, but can't seem to find an effective solution.

I have looked at these questions below, but they did help (didn't mentioned how to unload data or why the new data is not replacing the old data.):

xml data to dynamic text AS3 flash

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




As the others said, you're keeping the old output and add the new instead of replacing the old with the new. It's the linefield.htmlText = str + text;. Instead, overwrite your htmlText with the given (new) content.

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

People are also looking for solutions to the problem: php - Why can't I echo out a variable from an array?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.