0

I'm new to Javascript and to Flash, and I'm developing a browser Flash video recorder.

Right now, when I direct my browser to a certain URL, it asks for permission to access the webcam and starts recording - and streaming to a Red5 server on Ubuntu.

I now need to add a javascript button, which when clicked will start the recording, and when clicked again, will stop it. Can someone tell me how to play the .swf file only when the button is clicked? And how to stop playing it when the button is clicked again?

Thanks.

wrahool
  • 1,101
  • 4
  • 18
  • 42

2 Answers2

1

As Pete said, ExternalInterface is certainly what's needed to make function calls between a SWF and the surrounding HTML page.

You can also use swfobject to do cross-browser compatible SWF embedding/loading into a page dynamically.

I've made a little demo of the two features you're looking for here: http://akineticblog.com/fl/ExtIntDemo/index.html

The AS3 code for this is:

import flash.external.ExternalInterface;

var recording:Boolean = false;

//These are two TextFields instantiated on the stage as visual indicators
recordingTF.visible = false;
notRecordingTF.visible = true;

function recording_toggle():void {
    recording = ! recording;

    //Your actual record start/stop code would go here//
    recordingTF.visible = recording;
    notRecordingTF.visible = ! recording;
}

if (ExternalInterface.available) {
    //This registers the AS3-side function to the JS-side reference
    ExternalInterface.addCallback("recording_toggle", recording_toggle);
}

For the HTML/JS side, you can check the page source of the above link, but the main parts are:

function swf_load() {
    swfobject.embedSWF("ExtIntDemo.swf", "flashMovie", "500", "250", "10.1", "swf/expressinstall.swf", flashvars, params, attributes);
};

- to be called when you want to load in the SWF, replacing a div with the id 'flashMovie'.

And:

<button onclick="flashMovie.recording_toggle()">Toggle recording</button>
  • to send the 'recording_toggle' function call into the SWF itself.
hanenbro
  • 604
  • 7
  • 16
0

You can use ExternalInterface to communicate between JavaScript and AS3. After that it's just a case of making the button call the AS3 functions to you want to perform.

Pete TNT
  • 8,293
  • 4
  • 36
  • 45
  • Is there no way to "load" the ready made SWF when the button is clicked? – wrahool Aug 29 '13 at 09:27
  • Is the SWF already on the site on page load or do you want to dynamically embed the SWF? If you just want to embed the SWF you can use [SWFObject](https://code.google.com/p/swfobject/)-library to the work for you (see an [an example](http://stackoverflow.com/a/137349/2138943)). In any case if you want to have a JavaScript button that does something to the SWF you need to use ExternalInterface. – Pete TNT Aug 29 '13 at 09:57