我在 Flex/ActionScript 上遇到异步序列问题。这是一个例子:
private function start():void{
_menu = new MyMenu();
_screen.addElement(_menu);
//Here, some Mouse Event Listener to Menu Click
}
现在,让我们假设发生了对菜单的单击。
private function menuClick(event:Event):void{
removeMenu();
addMenu(event.SomethingPassedByTheClick);
}
现在,忘记事件处理程序的错误,让我们想想过程,好吗?我的问题是有时 addMenu() 在 removeMenu() 之前完成,这会导致错误。上面的脚本只是我的问题的逻辑表示,而不是真正的脚本。为了升起,我需要能够定义方法 addMenu() 必须等待 removeMenu() 在被调用之前完成。有什么想法吗?感谢您的关注。
编辑:
我的问题的一个更准确的例子:
private function createComplete():void{
_screenArray = new Array(
new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
startUp();
}
private function startUp():void{
//Some mathematical calculations that changes a few 0 to 1's.
addNewComponent();
}
private function addNewComponent():void{
removeAllComponents();
//More calculus on the array in order to create a component in vague space.
addComponentOnCalculatedArea(x, y);
//here is my problem: Sometimes, add Method is called before the removeAllComponents, which causes the new added component be removed by the removeAllComponents() method.
}
谢谢大家。我有错误的前提。我的数学计算出了什么问题,而不是调用方法的顺序。我注意到通过在脚本的每个方法中添加 trace() 。