Flex/ActionScript에서 비동기 시퀀스에 문제가 있습니다.ActionScript 3.0에서 메서드 시퀀스 연속 적용
이제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);
}
이제 이벤트 처리기의 오류를 잊어 버리십시오. 프로세스에 대해 생각해 보겠습니다. 내 문제는 오류가 발생하는 removeMenu() 전에 addMenu()가 끝나는 경우가 있습니다. 위의 스크립트는 실제 스크립트가 아니라 내 문제를 논리적으로 표현한 것입니다. sunup하기 위해 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.
}
감사합니다 여러분. 나는 잘못된 전제를 가지고 있었다. 수학의 계산 방식이 잘못되어 무엇이 잘못되었는지, 메서드 호출 순서는 아닙니다. 나는 Script의 각 메소드에 trace()를 추가하여 알아 차렸다.
독립 샘플 응용 프로그램을 게시 할 수 있습니까? 거기에 중간에 뭔가가 끼어들 수 없기 때문에 전적으로 여기를 잘 따랐는지 확신 할 수 없습니다. 생각해볼 때, removAllComponents 뒤에 무한 while 루프를 두어 아무 것도 실행되지 않는다는 것을 알아두기 – devshorts
'removeAllComponents' 메소드가 비동기 방식으로 실행되지 않으면'removeAllComponents'가 실행을 완료 할 때까지'addComponentOnCalculatedArea'를 실행할 수 없습니다. 디버거를 사용하여 트레이스를 배치하거나 단계별로 진행해야합니다. – shanethehat
무엇이 잘못되었는지 알아 보려면'removeAllComponents()'와'addNewComponent()'에있는 코드를 봐야합니다. 또한, 아마도'addComponentOnCalculatedArea()'. – iND