Problem Call ExternalInterface flash function

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.
  1. $("#webcam").get(0).actionSelfie("getCapture");
but I want make it on plugin like this:

  1.  this.Capture = function() {
  2.             if (opt.flash == true) {
  3.                 //this my problem
  4.                 camSelector.actionSelfie("getCapture");
  5.             } else {
  6.             }
  7. }
    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,,

    1. <!DOCTYPE HTML>
    2. <html>
    3. <head>
    4. <meta charset="utf-8"/>
    5. <meta http-equiv="content-type" content="text/html" />
    6. <meta name="author" content="Jasman" />
    7. <title>Untitled 3</title>
    8. <script src="js/swfobject.js"></script>
    9. <script src="js/jquery.js"></script>
    10. <script src="js/selfie.js"></script>
    11. <script type="text/javascript">

    12. function show_img(image){
    13. $("#result").html('<img src="' + image +'" width="320" height="240" style="border: 1px solid red"/>');
    14. }

    15. //for flash
    16. function getMessages(label) {
    17. $("#progress").html(label);
    18. };

    19. function getSnapshot(image) {
    20. show_img(image)
    21. };

    22. $(document).ready(function(){
    23. var MyCam = $("#webcam").Webcam({width: 320,height: 240}) ;
    24. $("#CaptureBtn").click(function(){
    25. //HTML5
    26. //var img = MyCam.Capture();
    27. //show_img(img);

    28. // I need run like this var img = MyCam.Capture();
    29. $("#webcam").get(0).actionSelfie("getCapture");

    30. });
    31. });
    32. </script>
    33. </head>
    34. <body>
    35. <label id="progress"></label>
    36. <video id="webcam"></video>
    37. <div id="result"></div>
    38. <input type="button" id="CaptureBtn" value="Capture" />
    39. </body>
    40. </html>

    My plugin

    1. if (!jQuery) {
    2. throw new Error("requires jQuery")
    3. }
    4. if (!jQuery) {
    5. throw new Error("requires swfobject")
    6. }
    7. (function(dev) {
    8. dev.fn.Webcam = function(options) {
    9. var default_options = {
    10. width: 320,
    11. height: 240
    12. };
    13. var opt = dev.extend({}, default_options, options);
    14. var ua = navigator.userAgent;
    15. ua = ua.toLowerCase();
    16. 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) || [];

    17. //var useFlash = false;
    18. var useFlash = true; //only test flash

    19. if (uaMatch[1] == "msie") {
    20. useFlash = true
    21. }
    22. if (uaMatch[1] == "mozilla" && parseFloat(uaMatch[2]) <= 17) {
    23. useFlash = true
    24. }
    25. if (uaMatch[1] == "webkit" && parseFloat(uaMatch[2]) <= 21) {
    26. useFlash = true
    27. }
    28. if (uaMatch[1] == "opera" && parseFloat(uaMatch[2]) <= 18) {
    29. useFlash = true
    30. }
    31. var flash_dir = "";
    32. $("script").each(function() {
    33. var e = /(selfie)/.exec(this.src);
    34. if (e) {
    35. flash_dir = this.src
    36. }
    37. });
    38. var flash_dir = flash_dir.replace(".js", ".swf");
    39. this.css('width', opt.width);
    40. this.css('height', opt.height);
    41. if (useFlash == true) {
    42. var flashvars = {
    43. width: opt.width,
    44. height: opt.height,
    45. zoom: "1"
    46. };
    47. var params = {};
    48. var attributes = {};
    49. swfobject.embedSWF(flash_dir, this.attr('id'), opt.width, opt.height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    50. var camSelector = $(this).get(0);
    51. } else {
    52. var camSelector = this.get(0);
    53. navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    54. navigator.getMedia({
    55. video: true,
    56. audio: false
    57. }, function(e) {
    58. if (navigator.mozGetUserMedia) {
    59. camSelector.mozSrcObject = e
    60. } else if (navigator.webkitGetUserMedia) {
    61. camSelector.src = window.webkitURL.createObjectURL(e)
    62. } else if (navigator.msGetUserMedia) {
    63. camSelector.src = window.URL.createObjectURL(e)
    64. } else {
    65. try {
    66. camSelector.src = window.URL.createObjectURL(e)
    67. } catch (t) {
    68. camSelector.src = e
    69. }
    70. }
    71. camSelector.play()
    72. }, function(e) {})
    73. }
    74. this.Capture = function() {
    75. if (useFlash == true) {
    76. //this my problem 
    77. camSelector.actionSelfie("getCapture");
    78. } else {
    79. this.append('<canvas id="jcanvas" style="visibility: hidden;"></canvas>');
    80. canvas = $("#jcanvas").get(0);
    81. canvas.width = opt.width;
    82. canvas.height = opt.height;
    83. canvas.getContext("2d").drawImage(camSelector, 0, 0, opt.width, opt.height);
    84. var img = canvas.toDataURL("image/png");
    85. $("#jcanvas").remove();
    86. return img;
    87. }
    88. }
    89. return this;
    90. }
    91. })(jQuery)

    Thanks