String 如果Objectsname取自字符串,如何使用Objects.function
我想知道这个概念是否可行: 情景: 一个阶段上的4个区域非常相似(例如网络摄像机会议,每个区域具有相同的功能) 按钮对象已编号(例如区域1有playbutton1、mutebutton1、namebutton1、namelabel1等) 每个区域都有一个关闭按钮,用于关闭/关闭该区域。(关闭1、关闭2、关闭3…) 我想归档以下内容:String 如果Objectsname取自字符串,如何使用Objects.function,string,flash,object,button,actionscript-2,String,Flash,Object,Button,Actionscript 2,我想知道这个概念是否可行: 情景: 一个阶段上的4个区域非常相似(例如网络摄像机会议,每个区域具有相同的功能) 按钮对象已编号(例如区域1有playbutton1、mutebutton1、namebutton1、namelabel1等) 每个区域都有一个关闭按钮,用于关闭/关闭该区域。(关闭1、关闭2、关闭3…) 我想归档以下内容: if(close1.isPressed){ function invisall(1); } /* * instead of writing * if(clos
if(close1.isPressed){
function invisall(1);
}
/*
* instead of writing
* if(close1.isPressed){
* playbutton1._visible=false;
* mutebutton1._visible=false;
* }else if(close2.isPressed){
* playbutton2._visible=false;
* mutebutton2._visible=false;
* etc. resulting in an enormous block.
* the interesting part. buttonNr gets added via String to become a real buttonname(eg
* playbutton1 as mentioned above).*/
function invisall(int buttonNr){
String newPlayButtonObjectName="playbutton"+buttonNr;
newPlayButtonObjectName._visible=false;
String newMuteButton="mutebutton"+buttonNr;
newMuteButton._visible=false;
}
this should do the trick via dynamic Nr at the end of each default button(eg
playbutton)
but ofc
"playbutton1"._visible=false;
doesnt work because playbutton1 is still a String.
how can i take the String as a Buttonname/ButtonObject?
do i need to write an new function? this would destroy the purpose of less code.
也许你喜欢这个主意。现在我将把这个区域分割成我放在舞台上的框架。这应该会有帮助
干杯
我希望这就是你想要的
function invisall(int buttonNr){
this["playbutton"+buttonNr]._visible=false;
this["mutebutton"+buttonNr]._visible=false;
}