2011-10-10 95 views
1

我必须使用actionscript 3.0,PHP和Mysql动态加载图像。我在数据库中有图像路径。现在我必须在Flash中显示图像。谁能帮我?在Flash中动态加载图像

+0

请帮帮我。我褪色了........ –

回答

1

你必须使用AS3 Loader类来做到这一点。 Loader类应该加载php脚本。 PHP脚本应该从MySQL数据库加载图像并显示它。它可能看起来像:

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'

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传递。

0

我不知道PHP的一部分,但在ActionScript最好是添加装载机,而不是阶段性增加它的内容:

  1. 在这种情况下,代码更简单,因为你不必处理完成事件在所有。
  2. 如果您尝试直接从不同服务器加载的图像访问'content'字段 - 您将获得安全性异常,并且必须将crossdomain.xml放置在带图像的服务器上(并且如果图像服务器不属于你)。

所以AS3部分看起来是这样的:

const loader:Loader = new Loader(); 
loader.load(new URLRequest(imageURL)); 
addChild(loader) 
0

检查这些从Flash /传道的Actionscript李布赖姆洛教程:
Introduction to AmfPHP part 2
Introduction to Zend AMF

如果你不知道,gotoandlearn.com是一切Flash的优秀资源。

希望这会有所帮助!

+0

我是新的网络。那么你可以通过简单的PHP来帮助我吗? –

+0

我刚刚做到了!你有没有看过视频?... – PatrickS

+0

我是新的网络,我preper简单的PHP。我可以使用php从数据库中拉出图像路径。你能告诉我如何在Flash中显示这些图像,也可以用作符号吗? –