Actionscript 3 加载MovieClips数组单击Btn数组
如何点击任意按钮将数组加载到数组的具体内容Teddy I感激(加载Movieclips数组点击按钮数组) var-teddy:Array=[home,about,products,services,contact]; 变量l:int=teddy.length; 对于(var j:int=0;jActionscript 3 加载MovieClips数组单击Btn数组,actionscript-3,Actionscript 3,如何点击任意按钮将数组加载到数组的具体内容Teddy I感激(加载Movieclips数组点击按钮数组) var-teddy:Array=[home,about,products,services,contact]; 变量l:int=teddy.length; 对于(var j:int=0;j
// set as invisible
myArray[i].visible = false;
// set as visible
myArray[i].visible = true;
否则,如果每次都必须重新创建对象,则必须为对象指定对象类,并使用对象类调用它们
var mc = new myObjClass();
希望有帮助。好的,我会再帮你一次。但是你必须和那些试图帮助你的人谈谈。如果你不明白,就问吧。另外,至少要对你的问题投上有用的一票,或者如果效果不错,就标上正确的一票。否则,没有人想输入教程(因为有谷歌和ActionScript手册) 测试我显示的代码的最佳方法是。。。创建一个新的空白FLA文件,并保存到某个文件夹中。现在转到属性(ctrl+F3)并在类中:框中键入数组按钮\u v1(再次按enter键并保存FLA)。现在,您可以单击类:框旁边的铅笔图标来编辑您的类文档。您将用我的代码替换该自动代码,如下所示。。(照片中:MyClass变成了数组按钮\u v1) 图片来源:Adobe.com 您的库中还需要5个movieClips(ctrl+L)。这是一个用作按钮MC的movieClip,然后在单击时在舞台上添加四个其他movieClip。必须右键单击库中的每一个并选择“属性”,然后在链接部分勾选导出Actionscript,并在此处显示的类框中使用以下名称
package
{
//** You will need more IMPORTS as you use other Flash features (APIs)
//** But these two is enough here.. check AS3 manual or tutorials for what to add
import flash.display.MovieClip;
import flash.events.*;
public class Array_buttons_v1 extends MovieClip
{
public var MC_Array:Array = []; //new array is empty
public var Btn_Array:Array = [];
public var MC_0 : MC1 = new MC1();
public var MC_1 : MC2 = new MC2();
public var MC_2 : MC3 = new MC3();
public var MC_3 : MC4 = new MC4();
public var btn_0 : btn_MC = new btn_MC();
public var btn_1 : btn_MC = new btn_MC();
public var btn_2 : btn_MC = new btn_MC();
public var btn_3 : btn_MC = new btn_MC();
public var mClips_holder : MovieClip = new MovieClip;
public var buttons_holder : MovieClip = new MovieClip;
public function Array_buttons_v1()
{
//** Update MC array.. items are counted from 0,1,2,3 (NOT 1,2,3,4)
MC_Array = [ MC_0, MC_1, MC_2, MC_3 ]; //meaning array pos [ 0, 1, 2, 3 ]
stage.addChild( mClips_holder ); //will hold
mClips_holder.y = 70; //move down so its not blocking anything
//** Update Buttons array
Btn_Array = [ btn_0, btn_1, btn_2, btn_3 ];
stage.addChild( buttons_holder ); //put Button holder on stage
//buttons_holder.addChild( Btn_Array [0] ); //put Buttons inside holder
var insert_pos:int = 0; //will use as screen "adding position" for buttons
//** To add all in array.. we start from pos of 0 and count up to 3
//** For every count number we do instructions inside { } until count finished
for (var arr_pos:int = 0; arr_pos <= 3; arr_pos++) //create some counter
{
trace("position inside the array is now : " + arr_pos);
//** setup instance Names for movieClips inside the MC Array
//** later you can access each one by name using "getChildByName" as MC_1 or MC_2 etc..
MC_Array[arr_pos].name = "MC_" + ( String(arr_pos) );
//** setup Buttons (names, clicked functions etc )..
Btn_Array[arr_pos].name = "button_" + ( String(arr_pos) );
Btn_Array[arr_pos].buttonMode = true; //make clickable before adding to screen
Btn_Array[arr_pos].addEventListener(MouseEvent.CLICK, button_Clicked);
buttons_holder.addChildAt( Btn_Array [arr_pos], arr_pos ); //add to container
buttons_holder.getChildAt(arr_pos).x = insert_pos;
trace("pos of btn is now : " + buttons_holder.getChildAt(arr_pos).x);
//update the adding position amount
insert_pos += 50; //add +50 pixels distance for next item
} //end For loop
}
public function button_Clicked ( evt :MouseEvent ) : void
{
//** Use "evt" because it matches with above "evt:MouseEvent" for access
trace( "Button name: " + evt.currentTarget.name + " ..was clicked" );
//** Now you can use IF statement to run another function(s)
//if (evt.currentTarget.name == "button_0") { some_Test(); }
//** or Use SWITCH statement (better and easier)
switch (evt.currentTarget.name)
{
case "button_0" :
//mClips_holder.addChild(MC_0); //** can be done like this ..
mClips_holder.addChild( MC_Array[0] ); //but you wanted from array so do this way..
mClips_holder.getChildByName("MC_0").x = 0;
some_Test(); //to do some other function
//** to stop this button listening for mouse clicked
//Btn_Array[0].removeEventListener(MouseEvent.CLICK, button_Clicked);
break;
case "button_1" :
mClips_holder.addChild(MC_1);
mClips_holder.getChildByName("MC_1").x = 40;
//Btn_Array[1].removeEventListener(MouseEvent.CLICK, button_Clicked);
break;
case "button_2" :
mClips_holder.addChild(MC_2);
mClips_holder.getChildByName("MC_2").x = 80;
//Btn_Array[2].removeEventListener(MouseEvent.CLICK, button_Clicked);
break;
case "button_3" :
mClips_holder.addChild(MC_3);
mClips_holder.getChildByName("MC_3").x = 120;
break;
} //end Switch/Case
}
public function some_Test ( ) : void
{
trace(" ### This is some other function... do extra things in this section");
//your extra code here..
}
}
}
包
{
//**在使用其他Flash功能(API)时,您将需要更多的导入
//**但这两个在这里就足够了。请查看AS3手册或教程以了解需要添加的内容
导入flash.display.MovieClip;
导入flash.events.*;
公共类数组_按钮_v1扩展了MovieClip
{
public var MC_数组:数组=[];//新数组为空
公共变量Btn_数组:数组=[];
公共变量MC_0:MC1=新的MC1();
公共变量MC_1:MC2=新的MC2();
公共变量MC_2:MC3=新的MC3();
公共变量MC_3:MC4=新的MC4();
公共变量btn_0:btn_MC=new btn_MC();
公共变量btn_1:btn_MC=new btn_MC();
公共变量btn_2:btn_MC=new btn_MC();
公共变量btn_3:btn_MC=new btn_MC();
公共var mClips_持有人:MOVICLIP=新MOVICLIP;
公共var按钮\ U支架:MOVICLIP=新MOVICLIP;
公共函数数组_按钮_v1()
{
//**更新MC数组..项目从0,1,2,3开始计数(不是1,2,3,4)
MC_数组=[MC_0,MC_1,MC_2,MC_3];//表示数组位置[0,1,2,3]
stage.addChild(mClips_holder);//将保持
mClips_holder.y=70;//向下移动,这样它就不会阻塞任何东西
//**更新按钮数组
Btn_数组=[Btn_0,Btn_1,Btn_2,Btn_3];
stage.addChild(按钮座);//将按钮座放在舞台上
//buttons_holder.addChild(Btn_数组[0]);//将按钮放在holder内
var insert_pos:int=0;//将用作按钮的“添加位置”屏幕
//**要添加数组中的所有元素,我们从0开始,最多数到3
//**对于每个计数数,我们在{}内执行指令,直到计数完成
对于(var arr_pos:int=0;arr_pos)您的代码格式不正确,您的问题也不清楚。您好,上次我打字太快,所以我更新了一点以帮助您。请重新阅读并重新粘贴此新代码(尽管有一些小更改,您可能理解得足够多,甚至不需要此新编辑,但以防万一。。。(附言:很高兴它对你有用)
package
{
//** You will need more IMPORTS as you use other Flash features (APIs)
//** But these two is enough here.. check AS3 manual or tutorials for what to add
import flash.display.MovieClip;
import flash.events.*;
public class Array_buttons_v1 extends MovieClip
{
public var MC_Array:Array = []; //new array is empty
public var Btn_Array:Array = [];
public var MC_0 : MC1 = new MC1();
public var MC_1 : MC2 = new MC2();
public var MC_2 : MC3 = new MC3();
public var MC_3 : MC4 = new MC4();
public var btn_0 : btn_MC = new btn_MC();
public var btn_1 : btn_MC = new btn_MC();
public var btn_2 : btn_MC = new btn_MC();
public var btn_3 : btn_MC = new btn_MC();
public var mClips_holder : MovieClip = new MovieClip;
public var buttons_holder : MovieClip = new MovieClip;
public function Array_buttons_v1()
{
//** Update MC array.. items are counted from 0,1,2,3 (NOT 1,2,3,4)
MC_Array = [ MC_0, MC_1, MC_2, MC_3 ]; //meaning array pos [ 0, 1, 2, 3 ]
stage.addChild( mClips_holder ); //will hold
mClips_holder.y = 70; //move down so its not blocking anything
//** Update Buttons array
Btn_Array = [ btn_0, btn_1, btn_2, btn_3 ];
stage.addChild( buttons_holder ); //put Button holder on stage
//buttons_holder.addChild( Btn_Array [0] ); //put Buttons inside holder
var insert_pos:int = 0; //will use as screen "adding position" for buttons
//** To add all in array.. we start from pos of 0 and count up to 3
//** For every count number we do instructions inside { } until count finished
for (var arr_pos:int = 0; arr_pos <= 3; arr_pos++) //create some counter
{
trace("position inside the array is now : " + arr_pos);
//** setup instance Names for movieClips inside the MC Array
//** later you can access each one by name using "getChildByName" as MC_1 or MC_2 etc..
MC_Array[arr_pos].name = "MC_" + ( String(arr_pos) );
//** setup Buttons (names, clicked functions etc )..
Btn_Array[arr_pos].name = "button_" + ( String(arr_pos) );
Btn_Array[arr_pos].buttonMode = true; //make clickable before adding to screen
Btn_Array[arr_pos].addEventListener(MouseEvent.CLICK, button_Clicked);
buttons_holder.addChildAt( Btn_Array [arr_pos], arr_pos ); //add to container
buttons_holder.getChildAt(arr_pos).x = insert_pos;
trace("pos of btn is now : " + buttons_holder.getChildAt(arr_pos).x);
//update the adding position amount
insert_pos += 50; //add +50 pixels distance for next item
} //end For loop
}
public function button_Clicked ( evt :MouseEvent ) : void
{
//** Use "evt" because it matches with above "evt:MouseEvent" for access
trace( "Button name: " + evt.currentTarget.name + " ..was clicked" );
//** Now you can use IF statement to run another function(s)
//if (evt.currentTarget.name == "button_0") { some_Test(); }
//** or Use SWITCH statement (better and easier)
switch (evt.currentTarget.name)
{
case "button_0" :
//mClips_holder.addChild(MC_0); //** can be done like this ..
mClips_holder.addChild( MC_Array[0] ); //but you wanted from array so do this way..
mClips_holder.getChildByName("MC_0").x = 0;
some_Test(); //to do some other function
//** to stop this button listening for mouse clicked
//Btn_Array[0].removeEventListener(MouseEvent.CLICK, button_Clicked);
break;
case "button_1" :
mClips_holder.addChild(MC_1);
mClips_holder.getChildByName("MC_1").x = 40;
//Btn_Array[1].removeEventListener(MouseEvent.CLICK, button_Clicked);
break;
case "button_2" :
mClips_holder.addChild(MC_2);
mClips_holder.getChildByName("MC_2").x = 80;
//Btn_Array[2].removeEventListener(MouseEvent.CLICK, button_Clicked);
break;
case "button_3" :
mClips_holder.addChild(MC_3);
mClips_holder.getChildByName("MC_3").x = 120;
break;
} //end Switch/Case
}
public function some_Test ( ) : void
{
trace(" ### This is some other function... do extra things in this section");
//your extra code here..
}
}
}