在 Flash 中动态加载图像 [英] Load image dynamically in Flash
问题描述
我必须使用 actionscript 3.0、PHP 和 Mysql 动态加载图像.我在数据库中有图像路径.现在如何在 Flash 中显示图像?
I have to load image dynamically using actionscript 3.0, PHP and Mysql. I have the image path in the database. Now how to show the image in Flash?
推荐答案
你必须使用 AS3 Loader 类来做到这一点.加载器类应该加载 php 脚本.PHP 脚本应该从 MySQL 数据库加载图像并显示它.它可能看起来像这样:
you have to use AS3 Loader class to do that. Loader class should load php script. Php script should load image from MySQL database and display it. It could look like that:
AS3:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ImageLoaded);
loader.load(new URLRequest(urlToYourPhpScript));
function ImageLoaded(e:Event) {
addChild(e.target.loader.content);
}
其中 urlToYourPhpScript
可以包含一些 get 变量来识别您的图像:urlToYourPhpScript = 'http://www.example.com/?imageid=10'
where urlToYourPhpScript
can contain some get variables to identify your image: urlToYourPhpScript = 'http://www.example.com/?imageid=10'
PHP:
$link = mysql_connect("localhost", "username", "password") or die("Error: " . mysql_error());
// select our database
mysql_select_db("test") or die(mysql_error());
// get the image from the db
$sql = "SELECT image FROM images WHERE id=".$_GET['imageid'];
// the result of the query
$result = mysql_query("$sql") or die("Query error: " . mysql_error());
// set the header for the image
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
// close the db link
mysql_close($link);
其中 $_GET['imageid']
是从 AS3 传递的用于识别图像的参数.
where $_GET['imageid']
is a parameter passed from AS3 for identyfying your image.
这篇关于在 Flash 中动态加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!