It seems OpenLaszlo can run on AIR. What's less obvious is whether OpenLaszlo apps can use the AIR-specific APIs, like file system access. If so, how exactly is this done?
问题:
回答1:
While I don't have any specifics, the article you linked mentions that his application window can be dragged and closed. Those are AIR-only APIs (see the NativeWindow class), so presumably what you're asking about must be possible to some extent.
However, my understanding is that OpenLaszlo tries not to implement things that can be done in Flash but not (say) DHTML, so it may be less obvious how to do things like local file access. Probably you'll want to download the source linked in the article and see how he implemented the window drag/close.
回答2:
OpenLaszlo does implement features which are available in certain runtimes only. That's true for MP3 audio playback, Flash Player webcam and microphone access, RTMP streaming. The OpenLaszlo compiler supports inserting ActionScript code directly into scripts and methods.
Here is an example application which catches the Event.DEACTIVATE and Event.ACTIVATE events, and lets you exit the application by clicking/touching the red view.
ActionScript 3 APIs can be imported using the <passthrough> tag - which can be used inside the canvas, class definitions or any tag instance in your code.
<canvas bgcolor="#ffffff" debug="false" height="100%" width="100%">
<passthrough when="$as3">
import flash.events.Event;
import flash.desktop.NativeApplication;
</passthrough>
<handler name="oninit">
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, __onDeactivate);
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, __onActivate);
</handler>
<method name="__onActivate" args="ev">
Debug.info("onActivate");
Debug.info("frame rate is " + this.getDisplayObject().stage.frameRate)
</method>
<method name="__onDeactivate" args="ev">
Debug.info("onDeactivate");
Debug.info("frame rate is " + this.getDisplayObject().stage.frameRate)
</method>
<view width="80%" height="50%" bgcolor="red" clickable="true">
<passthrough>
import flash.desktop.NativeApplication;
</passthrough>
<handler name="onclick">
NativeApplication.nativeApplication.exit();
</handler>
</view>
</canvas>
If you want code to be executed for the SWFx runtime only, you can check put that code into blocks checking the $as3 property:
if ($as3) {
// Insert some code for the SWFx runtime or AIR applications only
}
Using the approach, it's easy to re-use LZX code for either DHTML, SWFx or AIR applications.