如何提高 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"/>
I am working on my first Adobe Flex application, and have a code section that appears to be running very slowly (but it does function properly!).
CC_Output is a text control, all the other controls are checkboxes (CC, CC_Duration, etc.)
Any help would be greatly appreciated!
<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"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在真空中,该代码在我的笔记本电脑上运行良好(如果我添加 CC 控件)。
我重写了一些以快速退出,这在某些情况下可能会有所改善。
In a vacuum, that code runs fine on my laptop (if I add in a CC control).
I rewrote it a bit to fast exit and that might improve things a bit in some cases.
为您想要做的事情构建一个组件,然后将该组件导入到主应用程序中并使用。那么文件大小将会减小,性能将会提高。
build one component for what you want to do and import that component into main application and use. then file size will decrease and performance will increase.
奇怪的是它跑得很慢。代码中没有发生任何特别的事情。
是的,代码不干净,但这并不影响这里的性能。
尝试运行 Flex Profiler 并查找可能的瓶颈(如果存在)。
It strange that it runs slowly. Nothing special happens in the code.
Yes, the code is not clean, but that doesn't influence performance here.
Try to run Flex Profiler and find possible bottlenecks, if they exist.