AS3 的安全性能进一步提升啊,已经不让我访问其他域下面的东西了。
官方的说法,需要得到服务器的授权,并且有 crossdomain.xml,不过我们当然不可能往别人的服务器里面放东西啊(至少我的水平不行)!
经过和Harry的讨论,因为PHP没有跨域这个概念(需要服务器允许),所以就可以通过PHP来中转,实现跨域访问。(ASP,JSP也类似,这里就不谈了,因为俺不会 )
由于今天晚上还要上课,所以就先草草的写一下大概思路。
这个东西目前只能调用 JPG 文件,PHP服务器端需GD库。
其他东西以后有时间在搞吧。
PHP端:
$imgPath = $_POST['url'];
function imageCreateFromJpegEx($file)
{
$data = file_get_contents($file);
$im = @imagecreatefromstring($data);
$i = 0;
while (!$im)
{
$data = substr_replace($data, "", -3, -2);
$im = @imagecreatefromstring($data);
}
return $im;
}
$im = imageCreateFromJpegEx($imgPath);
imagejpeg( $im );
Flash调用方法:
function LoadImg(e:MouseEvent):void
{
//imgMovieClip为需要加载图片的MovieClip,目前好像不能用内置的组件UILoader来读取...
var imgURLRequest:URLRequest = new URLRequest('get_images.php');
var imgURLLoader:URLLoader = new URLLoader(imgURLRequest);
var imgLoader:Loader = new Loader();
var imgURL:String = URL_Input.text;
var imgURLVariable:URLVariables = new URLVariables();
//
imgURLVariable.url = imgURL;
//imgURL即为需要跨域访问图片的URL
//
imgURLRequest.data = imgURLVariable;
imgURLRequest.method = URLRequestMethod.POST;
//URLRequestMethod 要用POST
//
imgLoader.load(imgURLRequest);
imgMovieClip.addChild(imgLoader);
}
Copyright 2007-2008 51AS.com Extended in kingcms 鲁ICP备06001158号