我正在 Flash 中创建一个横幅广告,一旦页面加载,它会显示来自 XML 文件的 3 个随机图像。我的问题是它偶尔会重复。我已经包含了我的代码,有什么建议吗?
var pHeight:Number = 84;
var pWidth:Number = 120;
var listLoader:URLLoader = new URLLoader( new URLRequest("www.example.com/example.xml") );
var picLoader:Loader = new Loader();
listLoader.addEventListener(Event.COMPLETE, gotList);
function gotList(evt:Event):void {
var xmlData:XML = XML(listLoader.data);
var numImages:Number = xmlData.picture.length();
var stImage:String = xmlData.picture[Math.floor(numImages*Math.random())].toString();
picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotPic);
picLoader.load( new URLRequest(stImage) );
listLoader.removeEventListener(Event.COMPLETE, gotList);
}
function gotPic(evt:Event):void {
var thisBmp:Bitmap = Bitmap(evt.target.content);
thisBmp.x = 0;
thisBmp.y = 0;
var thisWidth:Number = thisBmp.width;
var thisHeight:Number = thisBmp.height;
thisBmp.scaleX = pWidth/thisWidth;
thisBmp.scaleY = pHeight/thisHeight;
addChild(thisBmp);
picLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, gotPic);
}