すべての ActionScript 3 ベースのランタイム (SWF10、SWF11、...) で、次のコードは F5 キーを押して OpenLaszlo アプリのリロードを有効にします。
<canvas>
<passthrough when="$as3">
import flash.events.Event;
</passthrough>
<handler name="oninit">
if ($as3) {
var sprite = this.getDisplayObject();
sprite.addEventListener(Event.ACTIVATE, onactivate)
sprite.addEventListener(Event.DEACTIVATE, ondeactivate);
}
</handler>
<method name="onactivate" args="e=null">
Debug.info('OpenLaszlo app is active, press F5 to reload');
</method>
<method name="ondeactivate" args="e=null">
Debug.info('OpenLaszlo SWF is inactive');
</method>
<switch><when property="$debug">
<!-- Reload SWF app when F5 is pressed -->
<command key="['f5']"
onselect="lz.Browser.callJS('document.location.reload(true)')"
active="$once{$as3}" />
</when></switch>
</canvas>
まず、 Flash ムービーのEvent.ACTIVATE
とイベントを追跡しています。Event.DEACTIVATE
Flash ムービーがフォーカスを受け取ると、Event.ACTIVATE
イベントが送信されます。F5 キーを押してリロードを有効にするには、<command />
タグが追加されますが、アプリケーションで $debug が有効になっている場合のみです。
<switch><when property="$debug">
<!-- Reload SWF app when F5 is pressed -->
<command key="['f5']"
onselect="lz.Browser.callJS('document.location.reload(true)')"
active="$once{$as3}" />
</when></switch>
onselect ハンドラーは、lz.Browser
オブジェクトを使用して現在のページの再読み込みをトリガーします。キー コマンドは、ActionScript 3 ランタイムでのみ有効です。これで、SWF ランタイムでアプリケーションをテストまたは開発しているときに、DHTML ランタイムで行う場合と同様に、F5 キーを押してリロードするだけです。