AS3 从 PHP 加载 PNG
我需要一些帮助来将 PNG 文件从服务器加载到我的 Flash 项目中。我想要做的是能够调用 PHP 页面并向其发送一个我可以做的变量。然后我想访问数据库并获取图像的路径,我也可以这样做。我不确定的是接下来该怎么办。 我需要做的是 PHP 以某种方式将 PNG 返回到 flash。我可以将 PNG 添加到 php 页面并以某种方式使用加载程序吗?我一直在谷歌搜索,但大多数教程似乎都在获取 PNG。
谢谢 本
I need some help with loading a PNG file from a server into my flash project. What I want to do it be able to call a PHP page and send it a variable which I can do. Then I want to access a db and get a path for the image, I can do this too. What I'm not sure about is what to do then.
What I need to happen is the PHP to return the PNG to flash somehow. Can I just add the PNG to the php page and use a loader somehow? I've been searching around google but most tutorials seem to be getting PNGs out.
Thanks
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上很容易。 :)
请注意,您可能还必须包含一些路径信息。不确定您的图像存储在哪里,但如果图像位于 /var/www/public/images 中,您需要将其添加到 file_get_contents 调用中。
补充:另外,如果您只想返回 PNG 的路径,您可以对 PHP 文件执行 URLRequest,让它找出图像所在的位置,然后返回 URL。这甚至更容易...我只是建议标准化数据交换协议,例如 XML 或(甚至更好)JSON...这样,如果您决定要突破 Flash 并进入浏览器技术,您的后台已经在等你了。
It is actually pretty easy. : )
Note that you may have to include some path info as well. Not sure where your images are stored, but if the image are in /var/www/public/images, you'd wany to prepend that into your file_get_contents call.
Added: also, if you just want to return a path to the PNG, you can do a URLRequest to a PHP file, let it figure out where the image lives, and return a URL. This is even easier... I'd just recommend standardizing on a data interchange protocol like XML or (even better) JSON... that way, if you ever decide that you want to break out of Flash and into browser technologies, your backend will already be waiting for you.
如果你可以将 url 返回到 flash 就足够了。
也许在一两毫秒内你什么也看不见。但一旦加载器加载了该 img,您就会看到它。
您必须输入返回的img url。所以不是返回img url 的网页的url。
如果将上述内容与 John Green - PageSpike 的答案结合起来,您可以使用我的代码,只要 php 页面是 John Green - PageSpike 他的答案中的页面,并且您传递而不是返回的 img,然后将 url 传递给带参数的php页面;
因此,该 url 现在是 John Green - PageSpike 脚本的链接,该脚本实际上将返回图像。
if you can just return the url to the flash it will be sufficient.
maybe for a millisec or two you just see nothing. But as soon as the loader has loaded the img you will see it.
You must input the returned img url. So not the url to the webpage that returns the img url.
If you combine the above with the answer of John Green - PageSpike you can use my code as long as the php page is that of the one in John Green - PageSpike his answer and you pass instead of the returned img then pass the url to the php page with parameter;
So the url is now the link to the script of John Green - PageSpike which will return infact the image.
正如 Jhon Green 所提到的,它会起作用
,但有时您可能还需要,即使您发送内容类型为 image/png 的标头,上述 url 也不起作用。快速提示是发送文件名本身,而不是其 id
为此,您可能需要使用 mod-rewrite。
As Jhon Green has mentioned, it will work
but some times you may need also need the above url will not work even if you send headers of content type image/png. Quick tip for that is to send file name itself instead if its id
For this you may need to use mod-rewrite.