Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 寻找一种更有效的清除控件的方法_Apache Flex_Actionscript 3_Flash Builder_Mxml - Fatal编程技术网

Apache flex 寻找一种更有效的清除控件的方法

Apache flex 寻找一种更有效的清除控件的方法,apache-flex,actionscript-3,flash-builder,mxml,Apache Flex,Actionscript 3,Flash Builder,Mxml,在main.mxml中,我有一组textInput控件、一个组合框和一些复选框,我希望能够通过某种循环清除它们。现在,我是这样做的: public function clearAll():void { customerIDInput.text = ""; listIDCombo.selectedItem = ""; listVersionInput.text = ""; suppressMasterFilesInput.text = ""; priorOrderSuppres

在main.mxml中,我有一组textInput控件、一个组合框和一些复选框,我希望能够通过某种循环清除它们。现在,我是这样做的:

public function clearAll():void
{
  customerIDInput.text = "";
  listIDCombo.selectedItem = "";
  listVersionInput.text = "";
  suppressMasterFilesInput.text = "";
  priorOrderSuppressInput.text = "";
  onePerSelectInput.text = "";
  geoCountOptionsInput.text = "";
  keyCodeInput.text = "";
  nthSelectInput.text = "";
  geoTypeInput.text = "";
  geoValueFromInput.text = "";
  latitudeInput.text = "";
  longitudeInput.text = "";
  begRadiusInput.text = "";
  endRadiusInput.text = "";
  geoSelectOmitCheck.selected = false;
  fieldIDInput.text = "";
  fieldValueInput.text = "";
  fieldSelectOmitCheck.selected = false;
  outputFieldCheck.selected = false;
}
for each (var ctrl:UIComponent in Application)
{
  switch(ctrl.className)
  {
    case TextInput:
我在上读了一篇文章,建议使用creationComplete事件将控件添加到ArrayCollection。我试过了,效果很好,但它并不比我现在拥有的更优雅。所有这些控件都是mxml格式的,不是由我用AS生成的。我也试过这样循环:

public function clearAll():void
{
  customerIDInput.text = "";
  listIDCombo.selectedItem = "";
  listVersionInput.text = "";
  suppressMasterFilesInput.text = "";
  priorOrderSuppressInput.text = "";
  onePerSelectInput.text = "";
  geoCountOptionsInput.text = "";
  keyCodeInput.text = "";
  nthSelectInput.text = "";
  geoTypeInput.text = "";
  geoValueFromInput.text = "";
  latitudeInput.text = "";
  longitudeInput.text = "";
  begRadiusInput.text = "";
  endRadiusInput.text = "";
  geoSelectOmitCheck.selected = false;
  fieldIDInput.text = "";
  fieldValueInput.text = "";
  fieldSelectOmitCheck.selected = false;
  outputFieldCheck.selected = false;
}
for each (var ctrl:UIComponent in Application)
{
  switch(ctrl.className)
  {
    case TextInput:

不过,我还是过不了那个阶段。我找不到引用控件值的方法。有人知道吗?

我可能会像你那样做。有没有令人信服的理由不这样做?考虑到命名约定,我猜您在编译时有明确数量的已定义控件。您似乎没有未知号码

您可以为组件的所有子级计算出一个循环:

for (var index:int=0;this.numChildren ; x++){
 var component : UIComponent = this.getChildAt(index) as UIComponent;
 if(component is TextInput){
   component.text = '';
 } else if (component is ListBase){
   component.selectedIndex = null;
 }
 // etc for other comp types
}

但是,似乎您添加了不适当的处理;使代码更难开发;而且更难阅读

真的,我试图限制代码行数。您的解决方案将为我提供大约10行,比我当前的解决方案少50%。但我明白你在说什么;我很清楚它应该做什么。@totbar不要害怕有更多的代码,特别是如果它使事情更容易理解和维护的话。选择任何给定的设计模式;我可以保证我可以用更少的代码做同样的事情。不过,它可能不会具有可扩展性、可理解性或可维护性。