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()を追加することで気づいた。
独立したサンプルアプリケーションを投稿することはできますか?私はそこに真ん中に何かが入り込むことができないので、私がここに完全に従っているかどうかはわかりません。考えてみると、removedAllComponentsの後に無限ループwhileループを置いて何も実行されないことに気づく – devshorts
'removeAllComponents'メソッドが非同期で実行されない限り、' removeComponentOnCalculatedArea'は 'removeAllComponents'の実行が完了するまで起動できません。いくつかトレースを展開するか、デバッガで実際に何が起きているかを確認する必要があります。 – shanethehat
何が間違っているのかを知るには、 'removeAllComponents()'と 'addNewComponent()'のコードを見る必要があります。また、おそらく 'addComponentOnCalculatedArea()'。 – iND