在百度经验里找到的AS3通过XML加载外部图片代码,求高手指点!
在百度经验里找到的AS3通过XML加载外部图片代码,如何改为自动加载的,而不是点击按钮加载?本人很菜,求教了!另附原文地址:http://jingyan.baidu.co...
在百度经验里找到的AS3通过XML加载外部图片代码,如何改为自动加载的,而不是点击按钮加载?本人很菜,求教了!
另附原文地址:http://jingyan.baidu.com/article/14bd256e130523bb6d26123c.html
//加载图片到容器中
function loadPic(path:String,cup:Sprite,index:int):void
{
var mLoader:Loader = new Loader();
mLoader.name = "loader" + index;
mLoader.load(new URLRequest(path));
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeLoad);
}
function completeLoad(e:Event):void {
var targetLoader:Loader = e.target.loader as Loader;
var index:int =int(targetLoader.name.slice(6));
var getPic:Bitmap = Bitmap(targetLoader.content);
var curentCup:Sprite = this["mc" + index] as Sprite;
getPic.width = curentCup.width;
getPic.height = curentCup.height;
curentCup.addChild(getPic);
}
//加载xml数据
function loadXMLData(path:String):void
{
var xLoader:URLLoader = new URLLoader();
xLoader.addEventListener(Event.COMPLETE,completeLoadData);
xLoader.load(new URLRequest(path));
}
function completeLoadData(e:Event):void
{
var mXML:XML = XML(e.target.data);
var len:int = int(mXML.pic.@amount);
for(var i:int = 0;i<len;i++)
{
var mPath:String = mXML.pic.path[i];
loadPic(mPath,this["mc"+i],i);
}
}
addMouseEvent();
function addMouseEvent():void
{
btnLoad.addEventListener(MouseEvent.CLICK,loadPicInfo);
}
function loadPicInfo(e:MouseEvent):void
{
loadXMLData("photo.xml");
}
最好可以QQ沟通 展开
另附原文地址:http://jingyan.baidu.com/article/14bd256e130523bb6d26123c.html
//加载图片到容器中
function loadPic(path:String,cup:Sprite,index:int):void
{
var mLoader:Loader = new Loader();
mLoader.name = "loader" + index;
mLoader.load(new URLRequest(path));
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeLoad);
}
function completeLoad(e:Event):void {
var targetLoader:Loader = e.target.loader as Loader;
var index:int =int(targetLoader.name.slice(6));
var getPic:Bitmap = Bitmap(targetLoader.content);
var curentCup:Sprite = this["mc" + index] as Sprite;
getPic.width = curentCup.width;
getPic.height = curentCup.height;
curentCup.addChild(getPic);
}
//加载xml数据
function loadXMLData(path:String):void
{
var xLoader:URLLoader = new URLLoader();
xLoader.addEventListener(Event.COMPLETE,completeLoadData);
xLoader.load(new URLRequest(path));
}
function completeLoadData(e:Event):void
{
var mXML:XML = XML(e.target.data);
var len:int = int(mXML.pic.@amount);
for(var i:int = 0;i<len;i++)
{
var mPath:String = mXML.pic.path[i];
loadPic(mPath,this["mc"+i],i);
}
}
addMouseEvent();
function addMouseEvent():void
{
btnLoad.addEventListener(MouseEvent.CLICK,loadPicInfo);
}
function loadPicInfo(e:MouseEvent):void
{
loadXMLData("photo.xml");
}
最好可以QQ沟通 展开
1个回答
展开全部
addMouseEvent();//执行函数
function addMouseEvent():void
{
btnLoad.addEventListener(MouseEvent.CLICK,loadPicInfo);//添加鼠标侦听事件
}
function loadPicInfo(e:MouseEvent):void
{
loadXMLData("photo.xml");//执行加载xml的函数
}
//------------------------------------------------------------------------------------------------------
看一下注解就可以理解了。所以,上面一段去掉,换成
loadXMLData("photo.xml");
就可以了。
function addMouseEvent():void
{
btnLoad.addEventListener(MouseEvent.CLICK,loadPicInfo);//添加鼠标侦听事件
}
function loadPicInfo(e:MouseEvent):void
{
loadXMLData("photo.xml");//执行加载xml的函数
}
//------------------------------------------------------------------------------------------------------
看一下注解就可以理解了。所以,上面一段去掉,换成
loadXMLData("photo.xml");
就可以了。
追问
求QQ号!~图片加载成功但是控制不了图片的大小该怎么修改呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询