我使用下面的代码制作了一个投资组合闪存。它工作正常,但我有一个问题。由于图片有不同的尺寸,当加载较小的图片时,之前的图片仍然在背景中。你能帮我告诉我如何只显示当前图片清除背景。
提前致谢
import flash.display.BitmapData;
var loader:Loader;
var loading:TextField = new TextField();
var image:Bitmap;
var xmlLoader:URLLoader = new URLLoader();
var files:Array= new Array();
var titles:Array= new Array();
var description:Array= new Array();
var index:int = 0;
var pictures:int = 0;
xmlLoader.load(new URLRequest("images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, readXML);
function readXML(e:Event):void {
XML.ignoreWhitespace = true;
var images:XML = new XML(e.target.data);
pictures = images.picture.length();
for (var i:Number=0; i<pictures; i++) {
titles[i]=images.picture[i].title.text();
files[i]=images.picture[i].file.text();
description[i]=images.picture[i].description.text();
}
load(0);
}
function load(index:int):void {
circle.visible = false;
loader=new Loader();
loader.load(new URLRequest(files[index]));
text_folio.text = titles[index];
description_folio.text = description[index];
//loader.contentLoaderInfo.addEventListener("progress",progressLoad);
loader.contentLoaderInfo.addEventListener("complete",completeLoad);
}
function progressLoad(e:Event):void {
loading.x=100;
loading.y=100;
stage.addChild(loading);
loading.text="Loading: ";
var tFormat:TextFormat=new TextFormat();
tFormat.size = 20;
tFormat.color = 0x888888;
loading.setTextFormat(tFormat);
}
function completeLoad(e:Event):void {
bigImg.mask = null;
image=Bitmap(loader.content);
bigImg.addChild(image);
//create the small image from the big image
var bmp:BitmapData = new BitmapData(bigImg.width, bigImg.height);
bmp.draw(bigImg);
var bitmap2:Bitmap = new Bitmap(bmp);
bitmap2.scaleX /=2;
bitmap2.scaleY /=2;
smallImg.addChild(bitmap2);
loader.contentLoaderInfo.removeEventListener("progress",progressLoad);
loader.contentLoaderInfo.removeEventListener("complete",completeLoad);
loader=null;
loading.text="";
loading.visible=false;
circle.visible = true;
bigImg.mask = circle;//add the circle mask to the big image
stage.addEventListener("enterFrame",mGlass);
}
function mGlass(e:Event) {
bigImg.x = (mouseX * -1);
bigImg.y = (mouseY * -1);
circle.x = (mouseX-150);
circle.y = (mouseY-150);
}
left.addEventListener(MouseEvent.CLICK, buttonLeft);
right.addEventListener(MouseEvent.CLICK, buttonRight);
function buttonRight(event:MouseEvent):void {
if (index == pictures-1)
index = 0;
else
index++;
load(index);
}
function buttonLeft(event:MouseEvent):void {
if (index == 0)
index = pictures-1;
else
index--;
load(index);
}