jeudi 19 novembre 2015

MySQL, PHP and AS3 - showing content depending on ID

I am using Flash CC to create an interactive map with a lot of information for particular sites. I am using MySQL and PHP to retrieve the information and then display it in flash. I am trying to dynamically change the site ID and then change the data displayed in flash.

I created a function on the frame, as well as link the package.

My PHP Code:

$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);
    $datatitle .= $row->Site_Name;

This is my action script package: package {

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

public class App extends MovieClip {
    public static const URL:String = 'http://weburl/get.php';

    private var _loader:URLLoader;
    private var _request:URLRequest;

    public function App():void {
        output(" ");

    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.text;
        field.text = str + "\n" + text;



My Code on Frame 1

function loadData():void {
internal var siteNumber = 2;

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


output(" ");

var randomParam:String = "?p=" + Math.floor(Math.random() * (10000000)) + "&sn=";
_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);

At the moment, the siteNumber is increasing, but not being applied to the URL. Any help would be appreciated.

I have tried the links below and they have not helped.

MySQL,PhP, and Flash As3 Data is not loading properly?

loading images and data from mysql into Flash using PHP?

Load images to a TileList from Mysql using PHP and XML on Flash CS5

Aucun commentaire:

Enregistrer un commentaire