0

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

2
  • 1
    @Fushy What you mean by "unload" ? Maybe field.htmlText = text; ...
    – akmozo
    Nov 25, 2015 at 9:17
  • 1
    Your function output() prepends field.htmlText with new content. Why are you doing this? akmozo is correct in the previous comment. Nov 25, 2015 at 11:27

1 Answer 1

0

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 line field.htmlText = str + text;. Instead, overwrite your htmlText with the given (new) content.

public function output(str:String):void {
    field.htmlText = str;
}
1
  • I just realized that the data displays correctly when i preview it (alt and enter), but doesnt show up at all when I open the .swf file on its own. Any advice for this?
    – Fushy
    Dec 4, 2015 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.