以下のコードを使用して、ポートフォリオのフラッシュを作成しました。正常に動作しますが、問題があります。画像のサイズが異なるため、小さい画像が読み込まれると、前の画像がまだ背景にあります。背景をクリアして現在の画像のみを表示する方法を教えてください。
前もって感謝します
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);
}