Problem Call ExternalInterface flash function
I made a plugin webcam, I can not make a function call ExternalInterface flash in my plugin.
is there someone who wants to help :),
The function work when not in the plugin.
- $("#webcam").get(0).actionSelfie("getCapture");
but I want make it on plugin like this:
- this.Capture = function() {
- if (opt.flash == true) {
- //this my problem
- camSelector.actionSelfie("getCapture");
- } else {
- }
- }
error message: actionSelfie is not a function,, function may be called, before the flash is loaded. I am really newbie using jquery: '(
The following is the full code,,
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="utf-8"/>
- <meta http-equiv="content-type" content="text/html" />
- <meta name="author" content="Jasman" />
- <title>Untitled 3</title>
- <script src="js/swfobject.js"></script>
- <script src="js/jquery.js"></script>
- <script src="js/selfie.js"></script>
- <script type="text/javascript">
-
- function show_img(image){
- $("#result").html('<img src="' + image +'" width="320" height="240" style="border: 1px solid red"/>');
- }
-
- //for flash
- function getMessages(label) {
- $("#progress").html(label);
- };
-
- function getSnapshot(image) {
- show_img(image)
- };
-
- $(document).ready(function(){
- var MyCam = $("#webcam").Webcam({width: 320,height: 240}) ;
- $("#CaptureBtn").click(function(){
- //HTML5
- //var img = MyCam.Capture();
- //show_img(img);
-
- // I need run like this var img = MyCam.Capture();
- $("#webcam").get(0).actionSelfie("getCapture");
-
- });
- });
- </script>
- </head>
- <body>
- <label id="progress"></label>
- <video id="webcam"></video>
- <div id="result"></div>
- <input type="button" id="CaptureBtn" value="Capture" />
- </body>
- </html>
My plugin
- if (!jQuery) {
- throw new Error("requires jQuery")
- }
- if (!jQuery) {
- throw new Error("requires swfobject")
- }
- (function(dev) {
- dev.fn.Webcam = function(options) {
- var default_options = {
- width: 320,
- height: 240
- };
- var opt = dev.extend({}, default_options, options);
- var ua = navigator.userAgent;
- ua = ua.toLowerCase();
- var uaMatch = /(chrome)[ \/]([\w.]+)/.exec(ua) || /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || [];
-
- //var useFlash = false;
- var useFlash = true; //only test flash
-
- if (uaMatch[1] == "msie") {
- useFlash = true
- }
- if (uaMatch[1] == "mozilla" && parseFloat(uaMatch[2]) <= 17) {
- useFlash = true
- }
- if (uaMatch[1] == "webkit" && parseFloat(uaMatch[2]) <= 21) {
- useFlash = true
- }
- if (uaMatch[1] == "opera" && parseFloat(uaMatch[2]) <= 18) {
- useFlash = true
- }
- var flash_dir = "";
- $("script").each(function() {
- var e = /(selfie)/.exec(this.src);
- if (e) {
- flash_dir = this.src
- }
- });
- var flash_dir = flash_dir.replace(".js", ".swf");
- this.css('width', opt.width);
- this.css('height', opt.height);
- if (useFlash == true) {
- var flashvars = {
- width: opt.width,
- height: opt.height,
- zoom: "1"
- };
- var params = {};
- var attributes = {};
- swfobject.embedSWF(flash_dir, this.attr('id'), opt.width, opt.height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
- var camSelector = $(this).get(0);
- } else {
- var camSelector = this.get(0);
- navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
- navigator.getMedia({
- video: true,
- audio: false
- }, function(e) {
- if (navigator.mozGetUserMedia) {
- camSelector.mozSrcObject = e
- } else if (navigator.webkitGetUserMedia) {
- camSelector.src = window.webkitURL.createObjectURL(e)
- } else if (navigator.msGetUserMedia) {
- camSelector.src = window.URL.createObjectURL(e)
- } else {
- try {
- camSelector.src = window.URL.createObjectURL(e)
- } catch (t) {
- camSelector.src = e
- }
- }
- camSelector.play()
- }, function(e) {})
- }
- this.Capture = function() {
-
if (useFlash == true) {
//this my problem
- camSelector.actionSelfie("getCapture");
- } else {
- this.append('<canvas id="jcanvas" style="visibility: hidden;"></canvas>');
- canvas = $("#jcanvas").get(0);
- canvas.width = opt.width;
- canvas.height = opt.height;
- canvas.getContext("2d").drawImage(camSelector, 0, 0, opt.width, opt.height);
- var img = canvas.toDataURL("image/png");
- $("#jcanvas").remove();
- return img;
- }
- }
- return this;
- }
- })(jQuery)
Thanks