ActionScript 3 在as3中加载图像时浏览crossdomain.xml文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 在as3中加载图像时浏览crossdomain.xml文件相关的知识,希望对你有一定的参考价值。

import flash.display.DisplayObject;
import flash.display.LoaderInfo;
import flash.system.LoaderContext;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
...
// this is where we create the loader:
var loader:Loader = new Loader();
// this forces the loader to look for a crossdomain.xml file
var lctx:LoaderContext = new LoaderContext(true);
// listen for the init event on the loader
loader.contentLoaderInfo.addEventListener(Event.INIT, doImgInit);
// load the image, here the path is not valid.. i made it up
loader.load(new URLRequest("http://www.cssq.com/dunno.png", lctx);
....
// inside of the doImgInit function
protected function doImgInit(evt:Event):void
{
	// get a reference to the LoaderInfo object in which the image is loaded
	var lInfo:LoaderInfo = evt.target as LoaderInfo;
	// this variable is used as reference to the image in the end.
	var dO:DisplayObject;
	// try to access the "content" property of the loader, if it works, there is a crossdomain.xml file.
	try{
		dO = lInfo.loader.content;
	}
	// if there wasn't one, we need to put the loader inside another object in order to manipulate it
	catch(err:SecurityError)
	{
		// create a new Sprite to contain the loaded image
		var sprt:Sprite = new Sprite();
		// add the loader to the sprite
		sprt.addChild(lInfo.loader);
		// get a reference to this sprite in the dO variable
		var dO:DisplayObject = sprt as DisplayObject;
	}
	// from here on you can do anything to the dO variable, rotate it, draw it unto a bitmapData, move it around..
	// but first don't forget to add to to some container that is on the stage so you can see it!
}

以上是关于ActionScript 3 在as3中加载图像时浏览crossdomain.xml文件的主要内容,如果未能解决你的问题,请参考以下文章

如何在 AS3 中加载图像精灵序列时减少内存使用量

ActionScript 3 AS3:在图像上放置叠加层

ActionScript 3 AS3:图像加载

As3 - 我需要在两个场景中加载 XML 文件吗?

ActionScript 3 as3全背景图像类

ActionScript 3 AS3获取图像的平均颜色