mardi 24 novembre 2015

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?

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

my AS3 package code:

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

  }


}

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();
                loadData();
            }
prev_site1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerprev_site1); 
            function mouseDownHandlerprev_site1(event:MouseEvent):void 
            { siteNumber = siteNumber - 1;

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

            }

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 were not useful:

xml data to dynamic text AS3 flash

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

Aucun commentaire:

Enregistrer un commentaire