dtrnish3637 2015-11-20 05:47
浏览 86
已采纳

MySQL,PHP和AS3 - 根据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;
}
die($data);

This is my action script package: package {

import flash.display.MovieClip;
import flash.events.Event;
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 = 'http://weburl/get.php';

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

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

    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.text;
        field.text = str + "
" + 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;
    trace(siteNumber);

}

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);
_loader.load(_request);             
stop();     
}   

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

  • 写回答

1条回答 默认 最新

  • drpp5680 2015-11-20 06:05
    关注

    I have changed the code on frame one (now only contains the button):

    import flash.events.Event;
    import flash.events.MouseEvent;
    next_site30.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler30n); 
                function mouseDownHandler30n(event:MouseEvent):void 
                { siteNumber = siteNumber + 1;
                    trace(siteNumber);
                    loadData();
                }
    prev_site30.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler30prev); 
                function mouseDownHandler30prev(event:MouseEvent):void 
                { siteNumber = siteNumber - 1;
                    trace(siteNumber);
                    loadData();
                }
    

    And this is the package Actionscript code:

    package {
    
    import flash.display.MovieClip;
    import flash.events.Event;
    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 = 'http://leonoravirtual.designsensetest.net.au/get.php';
    
        private var _loader:URLLoader;
        private var _request:URLRequest;
        public function App():void {
            output(" ");
            loadData();
        }
        var siteNumber:int = 2;
    
        public function loadData():void {
            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);
            _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.text;
            field.text = str + text;
        }
    
     }
    
    }
    

    This worked :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)