想请教各位,在flex中,如何做到以下效果
if(type==1){
显示一个radio
}else{
显示一个checkbox
}我的意思就是在flex中如何根据一个变量的值去决定界面是显示一个radio还是显示一个checkbox!

解决方案 »

  1.   

    没有了解过flex傻傻的猜一把如果flex是面向对象的:
    那么, 作为组件, radio和checkbox应该会有共同的超类(父类), 
    那么你定义一个超类的属性, 假设radio和checkbox都是Component的子类, 那么Component c = null;
    if(type == 1) {
      c = new radio
    } else {
      c = new checkbox
    }呵呵, 希望可以帮到你.
      

  2.   

    有两种方法:
    1、用as来创建元素
    if(type==1){ 
        var radio:RadioButton = new RadioButton();
        //接下来就是对该RadioButton 的位置、事件等等的处理了
    }else{ 
        var checkbox:CheckBox = new CheckBox();
        //类似上面的
    }
    2、在mxml里先创建出来,控制显示即可
    <mx:RadioButton x="174" y="312" id="radio" label="Radio" visible="false"/>
    <mx:CheckBox x="174" y="312" id="checkbox" label="checkbox" visible="false"/>
    if(type==1){ 
       radio.visible = true;
    }else{ 
       checkbox.visible = true;

      

  3.   

    我觉得。。你可以先把两个组件都放在页面上,用visible=false的属性来隐藏掉。。然后在你的代码里做判断
    if(type==1){ 
    radio 的visible=true;
    checkbox的visible=false;
    }else{ 
    radio 的visible=false;
    checkbox的visible=true;
    }就能解决你的问题希望对你有帮助