2009-11-27 89 views
0

我正在使用我的第一个Adobe Flex应用程序,并且有一段代码部分显示为运行速度非常慢(但它的功能正常!)。如何提高此Adobe Flex脚本的速度?

CC_Output是文本控件,所有其他控件的复选框(CC,CC_Duration等)

任何帮助将不胜感激!

<mx:Script>     


     private function updateLabel():void { 
      var HPI_Score:Number = 0; 
      if (CC.selected) {CC_Output.text = "CC/HPI - Brief";} 

      if (!CC.selected) { 
       CC_Output.text = "CC/HPI - Inadequate"; 
      } else { 

       if (CC_Duration.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Location.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Quality.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Severity.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Timing.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Context.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Modify.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Assoc.selected) {HPI_Score=HPI_Score+1;} 
       if (CC_Chronic_Dx.selected) {HPI_Score=HPI_Score+4;} 

       if (HPI_Score > 3) {CC_Output.text = "CC/HPI - Extended";} 
      } 
     } 

</mx:Script> 
<mx:TextArea id="LBL" x="262" y="28" enabled="true" visible="true" width="142"/> 
<mx:CheckBox x="10" y="71" label="Duration" id="CC_Duration" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="92" label="Location" id="CC_Location" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="113" label="Quality" id="CC_Quality" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="134" label="Severity" id="CC_Severity" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="155" label="Timing" id="CC_Timing" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="176" label="Context" id="CC_Context" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="197" label="Modifying Factors" id="CC_Modify" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="218" label="Assoc Signs/Symptoms" id="CC_Assoc" enabled="true" visible="true" click="updateLabel();"/> 
<mx:CheckBox x="10" y="239" label="Status of 3 Chronic Dx" id="CC_Chronic_Dx" enabled="true" visible="true" click="updateLabel();"/> 
<mx:Label x="10" y="29" text="CC/HPI" fontWeight="bold" id="CC_Output"/> 

+0

对我来说运行速度很快 – Amarghosh 2009-11-27 06:00:56

回答

1

在真空中,该代码在笔记本电脑上运行良好(如果我添加了CC控件)。

我将它重写了一下以便快速退出,并且在某些情况下可能会有所改进。

 private function updateLabel():void 
    { 
     const messageInadequate:String = "CC/HPI - Inadequate"; 
     const messageBrief:String = "CC/HPI - Brief"; 
     const messageExtended:String = "CC/HPI - Extended"; 

     if (!CC.selected) 
     { 
      CC_Output.text = messageInadequate; 
      return; 
     } 

     if (CC_Chronic_Dx.selected) 
     { 
      CC_Output.text = messageExtended; 
      return; 
     } 

     var HPI_Score:int = 0; 

     if (CC_Duration.selected) HPI_Score++; 
     if (CC_Location.selected) HPI_Score++; 
     if (CC_Quality.selected) HPI_Score++; 
     if (CC_Severity.selected) HPI_Score++; 
     if (CC_Timing.selected) HPI_Score++; 
     if (CC_Context.selected) HPI_Score++; 
     if (CC_Modify.selected) HPI_Score++; 
     if (CC_Assoc.selected) HPI_Score++; 

     if (4 > HPI_Score) 
     { 
      CC_Output.text = messageBrief; 
     } 
     else 
     { 
      CC_Output.text = messageExtended; 
     } 
    } 
0

建立你想做的事,并导入组件到主应用程序和使用什么样一个组成部分。那么文件大小会降低,性能会增加。

0

它奇怪,它运行缓慢。代码中没有什么特别的事情发生

是的,代码不干净,但这并不影响性能。

尝试运行Flex Profiler并查找可能的瓶颈(如果存在)。