我有一个3D轮播脚本..当点击其中一个实例时,它将加载一个外部swf(其中包含close_btn)作为其内容..它工作得很好......问题是如何使用close_btn删除外部加载的swf ...这是我在主时间轴中的代码:
var centerX:Number = stage.stageWidth / 2;
var centerY:Number = stage.stageHeight / 2;
var radiusX:Number = 180;
var radiusY:Number = 50;
var speed:Number = 0.1;
var minSpeed:Number = -0.15;
var maxSpeed:Number = 0.15;
var rangeSpeed:Number = maxSpeed - minSpeed;
var minY:Number = centerY - radiusY;
var maxY:Number = centerY + radiusY;
var rangeY:Number = maxY - minY;
var minScale:Number = 0.5;
var maxScale:Number = 1.2;
var rangeScale:Number = maxScale - minScale;
var my_loader:Loader = new Loader();
var itemArray:Array =[perkhidmatan, misi, tentang, members];
var fileNames : Array = ["perkhidmatan.swf", "misi.swf", "tentang.swf","members.swf",];
var canvas:MovieClip = new MovieClip();
addChild(canvas);
for (var i:Number = 0; i < itemArray.length; i++)
{
canvas.addChild(itemArray[i]);
itemArray[i].buttonMode = true;
itemArray[i].addEventListener(MouseEvent.CLICK, goToURL);
itemArray[i].itemAngle = Math.PI * 2 / itemArray.length * i;
itemArray[i].addEventListener(Event.ENTER_FRAME, animate);
}
function goToURL(e:MouseEvent):void {
for (var i:int = 0; i < itemArray.length; i++) {
if (e.currentTarget == itemArray[i]) {
my_loader.load(new URLRequest(fileNames[i]));
trace(fileNames[i]);
trace(my_loader);
addChild(my_loader);
itemArray[i].mouseEnabled = false;
itemArray[i].alpha = 0.5;
} else {
itemArray[i].mouseEnabled = true;
itemArray[i].alpha = 1;
}
}
}
function animate(e:Event):void
{
speed = mouseX / stage.stageWidth * rangeSpeed + minSpeed;
e.currentTarget.x = Math.cos(e.currentTarget.itemAngle) * radiusX + centerX;
e.currentTarget.y = Math.sin(e.currentTarget.itemAngle) * radiusY + centerY;
e.currentTarget.itemAngle += speed;
itemArray.sortOn("y");
for(var i:Number = 0; i < itemArray.length; i++)
{
canvas.setChildIndex(itemArray[i], i);
var pct:Number = (itemArray[i].y - minY) / rangeY;
var scale:Number = pct * rangeScale + minScale;
itemArray[i].scaleX = itemArray[i].scaleY = scale;
}
}
答案 0 :(得分:0)
好吧,听起来你想要在加载的swf中的显示对象中添加一个点击监听器,点击它时会从舞台上删除加载的swf。
所以这就是我要做的事情:
function goToURL(e:MouseEvent):void {
for (var i:int = 0; i < itemArray.length; i++) {
if (e.currentTarget == itemArray[i]) {
my_loader.contentLoaderInfo.addEventListener( Event.COMPLETE. onLoaderComplete );
my_loader.load(new URLRequest(fileNames[i]));
trace(fileNames[i]);
trace(my_loader);
//addChild(my_loader); //do not add the loader to this display object
itemArray[i].mouseEnabled = false;
itemArray[i].alpha = 0.5;
} else {
itemArray[i].mouseEnabled = true;
itemArray[i].alpha = 1;
}
}
}
function onLoaderComplete( e:Event ):void {
//set a variable called _loadedSwf as type MovieClip at the top
_loadedSwf = e.target.content;
_loadedSwf.close_btn.addEventListener( MouseEvent.CLICK, removeLoadedSwf );
addChild( _loadedSwf );
}
function removeLoadedSwf( e:MouseEvent ):void {
removeChild( _loadedSwf );
}
我没有测试过这个,但我相信这就是你要找的东西?无论哪种方式希望这可以帮助你!