この文書は Runtime社のホームページにある、http://www.runrev.com/revolution/developers/articles/tipoftheweek/2.html を勝手に邦訳したものです。この文書の文責はUDIにあり、またUDIはこの文書についての一切の債務を負いません。 間違いがありましたら eudio@chabashira.co.jp までお知らせ下さい。この文書は必要と思われる時に適宜アップデートされます。
Developers> Articles> Tip of the Week!
Tip of the Week! 2
idle ハンドラの代わりに "Send ..in" を使う
HyperCard と SuperCard では、周期的な作業をするのに idle メッセージを使う。 Revolution は idle コマンドをサポートするが、より強力で効率の良い選択肢を持っている。 Send コマンドである。あなたはいつでも idle 命令の代わりに Send コマンドを用いることが出来る。
例えば QuickTime player の currentTime を常時表示するスクリプトがある:
on idleこれは send コマンドを使うことで、もっと効率良く出来る:
put the currentTime of player "My Player" into field "Player Progress"
end idle
on showPlayerCurrentTimesend 文を実行してから 500ミリ秒後に "showPlayerCurrentTime" メッセージがそのオブジェクトに送られる。 Revolution エンジンはその間占有されることが無いので、ほかの仕事をすることが出来る。 500ミリ秒後に行われるメッセージの送受は、パフォーマンスに悪影響を与えない。
put the currentTime of player "My Player" into field "Player Progress"
send "showPlayerCurrentTime" to me in 500 milliseconds
end showPlayerCurrentTime
send "showPlayerCurrentTime" to me in 500 millisecondsこの showPlayerCurrentTime は以下の文でキャンセルすることが出来る:
put the result into lTimerID--lTimerID contains the message ID
cancel lTimerID待機状態にあるメッセージを調べるには、pendingMessages 関数を使う。この関数は送られる予定のメッセージのリストを返す。イベント送信が予約される度にこのリストにメッセージが追加され、そしてメッセージが送られる(或いは cancel コマンドでキャンセルされる)度にリストから削除される。
560,1005923747.953,showPlayerCurrentTime,button id 1003 of card id 1002 of stack "Untitled 1"first item はメッセージID。これは the result で得らるのと同じもので、メッセージをキャンセルするのに用いることが出来る。
cancel (item 1 of the pendingMessages)item 2 はメッセージを送る時間、item 3 は送られるメッセージ、item 4 はメッセージが送られるオブジェクトである。