I am having a audio recorder component which is currently in swf 10 environment. This uses the microphone activity level and other microphone api's while recording the audio. I am currently converting the application to dhtml runtime. Is it possible to use a swf 10 component in dhtml?
OpenLaszlo has an example application doing exactly that: The musicdhtml application, here is the link to the source code in SVN.
You have to create a 2nd OpenLaszlo SWF application, and embed that into the HTML page - as it's shown in the JSP page for the musicdhtml example.
lz.embed.swf({url: 'audiokernel.lzx?lzt=swf', bgcolor: '#eaeaea', width: '0', height: '0', id: 'audiokernel'});
lz.embed.dhtml({url: 'main.lzx?lzt=object&lzr=dhtml&_canvas_debug=false', bgcolor: '#ffffff', width: '100%', height: '150', id: 'lzdhtmlapp'});
As you can see, the audiokernel.lzx has a width and height set to 0, is therefore invisible. Integration of both applications is achieved by calling lz.embed.audiokernel.callMethod()
out of the SWF application, and by using lz.Browser.callJS()
in the DHTML app.
Here is the play button in audioplayer.lzx, showing how the play method of the audioplayer is called when the button is clicked:
<button width="40" height="22"
onclick="lz.embed.audiokernel.callMethod('audioplayer.play()')" >
And the onframe
handler in the audioplayer.lzx:
<handler name="onframe" args="f">
//Debug.write("Got frame", f);
lz.Browser.callJS('setCanAttr', null, 'frame', f);
</handler>
Using lz.Browser.callJS()
you can call any method in your DHTML application out of an SWF runtime app directly. The DHTML canvas
is defined as a global var (not a very good practice) in the JavaScript namespace. Any element with an ID you set on a view in DHTML can be target when using lz.Browser.callJS()
.