as3.0多个按钮加载多个swf代码怎么写
我有多个按钮但是只能加载一个。其他按钮怎么同时加载外部swf?就是一个按钮加载一个swf。很急啊。...
我有多个按钮 但是只能加载一个。其他按钮怎么同时加载外部swf?就是一个按钮加载一个swf。很急啊。
展开
1个回答
展开全部
你先新建个fla,然后打开组件面板,拖一个按钮组件到舞台,然后删除,把下面的代码贴到第一帧,然后放8个swf到fla的目录,并依次命名为mc_1.swf,mc_2.swf,...mc_8.swf,完成后调试这个fla看看是不是你想要的结果。
import fl.controls.Button;
stop();
var btNum:Number = 8;
var bt_x:Number = 50;
var bt_y:Number = 340;
var loader:Loader = new Loader();
var mcArr:Array = new Array();
for(var i:int = 1;i<=btNum;i++){
var button:Button = new Button();
if(i/4 <= 1){
button.x = (i-1) * 100 + bt_x + i * 10;
button.y = bt_y;
}else{
button.x = (i-1 - 4) * 100 + bt_x + (i-4) * 10;
button.y = bt_y + 30;
}
button.label = i+"";
button.addEventListener(MouseEvent.CLICK,clickHandle);
addChild(button);
}
function clickHandle(e:MouseEvent):void{
if(mcArr.length >= 1){
removeChild(mcArr[0]);
mcArr.splice(0,1);
}
var bt:Button = e.target as Button;
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest();
switch(bt.label){
case "1":
url.url = "mc_1.swf";
break;
case "2":
url.url = "mc_2.swf";
break;
case "3":
url.url = "mc_3.swf";
break;
case "4":
url.url = "mc_4.swf";
break;
case "5":
url.url = "mc_5.swf";
break;
case "6":
url.url = "mc_6.swf";
break;
case "7":
url.url = "mc_7.swf";
break;
case "8":
url.url = "mc_8.swf";
break;
}
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
loader.load(url);
}
function loadComplete(e:Event):void{
var mc:MovieClip = e.target.content as MovieClip;
addChild(mc);
mc.play();
mcArr.push(mc);
}
import fl.controls.Button;
stop();
var btNum:Number = 8;
var bt_x:Number = 50;
var bt_y:Number = 340;
var loader:Loader = new Loader();
var mcArr:Array = new Array();
for(var i:int = 1;i<=btNum;i++){
var button:Button = new Button();
if(i/4 <= 1){
button.x = (i-1) * 100 + bt_x + i * 10;
button.y = bt_y;
}else{
button.x = (i-1 - 4) * 100 + bt_x + (i-4) * 10;
button.y = bt_y + 30;
}
button.label = i+"";
button.addEventListener(MouseEvent.CLICK,clickHandle);
addChild(button);
}
function clickHandle(e:MouseEvent):void{
if(mcArr.length >= 1){
removeChild(mcArr[0]);
mcArr.splice(0,1);
}
var bt:Button = e.target as Button;
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest();
switch(bt.label){
case "1":
url.url = "mc_1.swf";
break;
case "2":
url.url = "mc_2.swf";
break;
case "3":
url.url = "mc_3.swf";
break;
case "4":
url.url = "mc_4.swf";
break;
case "5":
url.url = "mc_5.swf";
break;
case "6":
url.url = "mc_6.swf";
break;
case "7":
url.url = "mc_7.swf";
break;
case "8":
url.url = "mc_8.swf";
break;
}
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
loader.load(url);
}
function loadComplete(e:Event):void{
var mc:MovieClip = e.target.content as MovieClip;
addChild(mc);
mc.play();
mcArr.push(mc);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询