未捕获类型错误:无法读取属性';getBarCode';未定义的类型(JavaScript)

未捕获类型错误:无法读取属性';getBarCode';未定义的类型(JavaScript),javascript,jquery,asp.net-mvc,asp.net-mvc-4,Javascript,Jquery,Asp.net Mvc,Asp.net Mvc 4,我试图在我的MVC4项目中实现一个网络摄像头解码器,除了一个问题之外,我的一切都已经足够好用了。在调试过程中,我注意到当我点击decode按钮时,google chromes debugger for javascript中出现了一个错误,说明了以下“Uncaught TypeError:无法读取undefined的属性'getBarCode'。我假定它与onclick方法的格式有关(见下文),但是在多次尝试格式化它之后,我仍然得到相同的错误。我还包括了Js文件和我的cshtml视图 QR.cs

我试图在我的MVC4项目中实现一个网络摄像头解码器,除了一个问题之外,我的一切都已经足够好用了。在调试过程中,我注意到当我点击decode按钮时,google chromes debugger for javascript中出现了一个错误,说明了以下“Uncaught TypeError:无法读取undefined的属性'getBarCode'。我假定它与onclick方法的格式有关(见下文),但是在多次尝试格式化它之后,我仍然得到相同的错误。我还包括了Js文件和我的cshtml视图

QR.cshtml

@{
    ViewBag.Title = "Webcam";
}

        <script>
            //$(document).ready(function () {
                $("#webcam").scriptcam({
                    path:'~/Scripts/',
                    readBarCodes: 'QR_CODE',
                    onError: onError,
                    cornerRadius: 0,
                    onWebcamReady: onWebcamReady
                });
            //});

            function onError(errorId, errorMsg) {
                alert(errorMsg);
            }
            function changeCamera() {
                $.scriptcam.changeCamera($('#cameraNames').val());
            }
            function onWebcamReady(cameraNames, camera, microphoneNames, microphone, volume) {
                $.each(cameraNames, function (index, text) {
                    $('#cameraNames').append($('<option></option>').val(index).html(text))
                });
                $('#cameraNames').val(camera);
            }
        </script> 


        <div style="width:330px;float:left;">
            <object type="application/x-shockwave-flash" data="~/Scripts/scriptcam.swf" width="320" height="240" id="webcam" style="visibility: visible;"><param name="menu" value="false"><param name="wmode" value="direct"><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="true"><param name="flashvars" value="width=320&amp;height=240&amp;chatWindow=chatWindow&amp;path=&amp;zoom=1&amp;zoomChat=1&amp;rotate=0&amp;skewX=0&amp;skewY=0&amp;flip=0&amp;noFlashFound=%3Cp%3EYou%20need%20%3Ca%20href%3D%22http%3A%2F%2Fwww.adobe.com%2Fgo%2Fgetflashplayer%22%3EAdobe%20Flash%20Player%2011.7%3C%2Fa%3E%20to%20use%20this%20software.%3Cbr%2F%3EPlease%20click%20on%20the%20link%20to%20download%20the%20installer.%3C%2Fp%3E&amp;onError=function%20onError(errorId%2CerrorMsg)%20%7B%0A%09%09%09%09alert(errorMsg)%3B%0A%09%09%09%7D&amp;cornerRadius=0&amp;onWebcamReady=function%20onWebcamReady(cameraNames%2Ccamera%2CmicrophoneNames%2Cmicrophone%2Cvolume)%20%7B%0A%09%09%09%09%24.each(cameraNames%2C%20function(index%2C%20text)%20%7B%0A%09%09%09%09%09%24('%23cameraNames').append(%20%24('%3Coption%3E%3C%2Foption%3E').val(index).html(text)%20)%0A%09%09%09%09%7D)%3B%20%0A%09%09%09%09%24('%23cameraNames').val(camera)%3B%0A%09%09%09%7D&amp;id=webcam"></object>
            <div style="margin:5px;">
                <img src="webcamlogo.png" style="vertical-align:text-top">
                <select id="cameraNames" size="1" onchange="changeCamera()" style="width:245px;font-size:10px;height:25px;">
                <option value="0">In Built Camera</option></select>
            </div>
        </div>
        <div style="width:135px;float:left;">
            <p><button class="btn btn-small" id="btn1" onclick="$('#decoded').text($.scriptcam.getBarCode());">Decode image</button></p>
        </div>
        <div style="width:200px;float:left;">
            <p id="decoded"></p>
        </div>
@{
ViewBag.Title=“网络摄像头”;
}
//$(文档).ready(函数(){
$(“#网络摄像头”).scriptcam({
路径:“~/Scripts/”,
读取条形码:“QR_码”,
onError:onError,
转弯半径:0,
onWebcamReady:onWebcamReady
});
//});
函数onError(errorId,errorMsg){
警报(errorMsg);
}
函数changeCamera(){
$.scriptcam.changeCamera($('#cameraNames').val());
}
网络摄像头就绪功能(摄像头、摄像头、麦克风、麦克风、音量){
$.each(摄像机名称、函数(索引、文本){
$('#cameraNames').append($('').val(index.html(text))
});
$('cameraNames').val(摄像机);
}
内置照相机
解码图像

Scriptcam.js

(function($) {
    $.fn.scriptcam=function(options) {
        // merge passed options with default values
        var opts=$.extend({}, $.fn.scriptcam.defaults, options);
        // off we go
        return this.each(function() {
            // add flash to div
            opts.id=this.id; // add id of plugin to the options structure
            data=opts; // pass options to jquery internal data field to make them available to the outside world
            data.path=decodeURIComponent(data.path); // convert URI back to normal string
            $('#'+opts.id).html(opts.noFlashFound); // inject no flash found message
            // forward incoming flash movie calls to outgoing functions
            $.scriptcam.SC_promptWillShow=data.promptWillShow;
            $.scriptcam.SC_fileReady=data.fileReady;
            $.scriptcam.SC_fileConversionStarted=data.fileConversionStarted;
            $.scriptcam.SC_onMotion=data.onMotion;
            $.scriptcam.SC_onError=data.onError;
            $.scriptcam.SC_onHandLeft=data.onHandLeft;
            $.scriptcam.SC_onHandRight=data.onHandRight;
            $.scriptcam.SC_onWebcamReady=data.onWebcamReady;
            $.scriptcam.SC_connected=data.connected;
            $.scriptcam.SC_onPictureAsBase64=data.onPictureAsBase64;
            $.scriptcam.SC_disconnected=data.disconnected;
            $.scriptcam.SC_setVolume=data.setVolume;
            $.scriptcam.SC_timeLeft=data.timeLeft;
            $.scriptcam.SC_userLeft=data.userLeft;
            $.scriptcam.SC_userJoined=data.userJoined;
            $.scriptcam.SC_addChatText=function(value) {
                value = value.replace(":{", '<img src="'+data.path+'angry.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":-{", '<img src="'+data.path+'angry.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":)", '<img src="'+data.path+'smile.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":-)", '<img src="'+data.path+'smile.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":D", '<img src="'+data.path+'biggrin.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":-D", '<img src="'+data.path+'biggrin.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":O", '<img src="'+data.path+'ohmy.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":-O", '<img src="'+data.path+'ohmy.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":(", '<img src="'+data.path+'sad.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":-(", '<img src="'+data.path+'sad.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":p", '<img src="'+data.path+'tongue.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(":-p", '<img src="'+data.path+'tongue.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(";)", '<img src="'+data.path+'wink.gif" width="16" height="16" class="smiley"/>');
                value = value.replace(";-)", '<img src="'+data.path+'wink.gif" width="16" height="16" class="smiley"/>');
                $('#'+data.chatWindow).append(value+'<br/>');
                $('#'+data.chatWindow).animate({ scrollTop: $('#'+data.chatWindow).prop("scrollHeight") - $('#'+data.chatWindow).height() }, 100);
            }
            if (opts.canvasHeight && opts.canvasHeight) {
                var newWidth=opts.canvasWidth;
                var newHeight=opts.canvasHeight;
            }
            else {
                // no canvas dimensions given, make our own horizontal layout
                var newWidth=opts.width*opts.zoom;
                var newHeight=opts.height*opts.zoom;
                if (opts.chatRoom) {
                    newWidth=(opts.width*opts.zoom)+(opts.width*opts.zoomChat)+5; // make room for two horizontal video windows with a margin of 5
                    opts.posX=(opts.width*opts.zoom)+5;
                    newHeight=opts.height*Math.max(opts.zoom,opts.zoomChat);
                };
            }
            // make new dimensions are not below minimum flash size
            if (newWidth < 215) {
                newWidth=215;
            }
            if (newHeight < 138) {
                newHeight=138;
            }
            if (opts.rotate!=0 || opts.skewX!=0 || opts.skewY!=0 || opts.flip!=0 || opts.zoom!=1 || opts.zoomChat!=1) {
                // no GPU acceleration
                var params = {
                    menu: 'false',
                    wmode: 'window',
                    allowScriptAccess: 'always',
                    allowFullScreen: 'true'
                };
            }
            else {
                // GPU acceleration when no filter is used
                var params = {
                    menu: 'false',
                    wmode: 'direct',
                    allowScriptAccess: 'always',
                    allowFullScreen: 'true'
                };
            };
            // Escape all values contained in the flashVars (IE needs this)
            for (var key in opts) {
                opts[key] = encodeURIComponent(opts[key]);
            };
            if (fileExists(decodeURIComponent(data.path)+'scriptcam.swf')) {
                swfobject.embedSWF(decodeURIComponent(data.path)+'scriptcam.swf', opts.id, newWidth, newHeight, '11.6', false, opts, params);
            }
            else {
                alert(decodeURIComponent(data.path)+'scriptcam.swf not found, please check the path parameter');
            }
        });
    };

    function fileExists(url) {
        var http = new XMLHttpRequest();
        http.open('HEAD', url, false);
        http.send();
        return http.status==200;
    }

    $.scriptcam={};

    // outgoing functions (calling the flash movie)

    $.scriptcam.getFrameAsBase64=function() {
        return $('#'+data.id).get(0).SC_getFrameAsBase64();
    }

    $.scriptcam.version=function() {
        return $('#'+data.id).get(0).SC_version();
    }

    $.scriptcam.hardwareacceleration=function() {
        return $('#'+data.id).get(0).SC_hardwareacceleration();
    }

    $.scriptcam.getMotionParameters=function() {
        $('#'+data.id).get(0).SC_getMotionParameters();
    }

    $.scriptcam.getBarCode=function() {
        return $('#'+data.id).get(0).SC_getBarCode();
    }

    $.scriptcam.startRecording=function() {
        $('#'+data.id).get(0).SC_startRecording();
    }

    $.scriptcam.pauseRecording=function() {
        $('#'+data.id).get(0).SC_pauseRecording();
    }

    $.scriptcam.resumeRecording=function() {
        $('#'+data.id).get(0).SC_resumeRecording();
    }

    $.scriptcam.closeCamera=function() {
        $('#'+data.id).get(0).SC_closeCamera();
    }

    $.scriptcam.changeVolume=function(value) {
        $('#'+data.id).get(0).SC_changeVolume(value);
    }

    $.scriptcam.sendMessage=function(value) {
        $('#'+data.id).get(0).SC_sendMessage(value);
    }

    $.scriptcam.playMP3=function(value) {
        $('#'+data.id).get(0).SC_playMP3(value);
    }

    $.scriptcam.changeCamera=function(value) {
        $('#'+data.id).get(0).SC_changeCamera(value);
    }

    $.scriptcam.changeMicrophone=function(value) {
        $('#'+data.id).get(0).SC_changeMicrophone(value);
    }

    // set javascript default values (flash default values are managed in the swf file)
    $.fn.scriptcam.defaults={
        width:320,
        height:240,
        chatWindow:'chatWindow',
        path:'',
        zoom:1,
        zoomChat:1,
        rotate:0,
        skewX:0,
        skewY:0,
        flip:0,
        noFlashFound:'<p>You need <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player 11.7</a> to use this software.<br/>Please click on the link to download the installer.</p>'
    };
})(jQuery);

// incoming functions (calls coming from flash) - must be public and forward calls to the scriptcam plugin

function SC_onError(errorId,errorMsg) {
    $.scriptcam.SC_onError(errorId,errorMsg);
}

function SC_fileReady(fileName) {
    $.scriptcam.SC_fileReady(fileName);
}

function SC_fileConversionStarted(fileName) {
    $.scriptcam.SC_fileConversionStarted(fileName);
}

function SC_onMotion(decodedString) {
    $.scriptcam.SC_onMotion(decodedString);
}

function SC_promptWillShow() {
    $.scriptcam.SC_promptWillShow();
}
function SC_onHandLeft() {
    $.scriptcam.SC_onHandLeft();
}
function SC_onHandRight() {
    $.scriptcam.SC_onHandRight();
}
function SC_onWebcamReady(cameraNames,camera,microphoneNames,microphone) {
    $.scriptcam.SC_onWebcamReady(cameraNames,camera,microphoneNames,microphone);
}

function SC_onPictureAsBase64(value) {
    $.scriptcam.SC_onPictureAsBase64(value);
}

function SC_connected() {
    $.scriptcam.SC_connected();
}

function SC_disconnected() {
    $.scriptcam.SC_disconnected();
}

function SC_setVolume(value) {
    $.scriptcam.SC_setVolume(value);
}

function SC_onMotion(motion,brightness,color,motionx,motiony) {
    $.scriptcam.SC_onMotion(motion,brightness,color,motionx,motiony);
}

function SC_timeLeft(value) {
    $.scriptcam.SC_timeLeft(value);
}

function SC_addChatText(value) {
    $.scriptcam.SC_addChatText(value);
}

function SC_userJoined(value) {
    $.scriptcam.SC_userJoined(value);
}

function SC_userLeft(value) {
    $.scriptcam.SC_userLeft(value);
}
(函数($){
$.fn.scriptcam=函数(选项){
//将传递的选项与默认值合并
var opts=$.extend({},$.fn.scriptcam.defaults,options);
//我们走吧
返回此值。每个(函数(){
//将flash添加到div
opts.id=this.id;//将插件的id添加到选项结构中
data=opts;//将选项传递给jquery内部数据字段,以使外部世界可以使用它们
data.path=decodeURIComponent(data.path);//将URI转换回普通字符串
$('#'+opts.id).html(opts.noFlashFound);//注入未找到flash的消息
//将传入的flash电影调用转发到传出函数
$.scriptcam.SC_promptWillShow=data.promptWillShow;
$.scriptcam.SC_fileReady=data.fileReady;
$.scriptcam.SC_fileConversionStarted=data.fileConversionStarted;
$.scriptcam.SC_onMotion=data.onMotion;
$.scriptcam.SC_onError=data.onError;
$.scriptcam.SC_onHandLeft=data.onHandLeft;
$.scriptcam.SC_onHandRight=data.onHandRight;
$.scriptcam.SC_onWebcamReady=data.onWebcamReady;
$.scriptcam.SC_connected=data.connected;
$.scriptcam.SC_onPictureAsBase64=data.onPictureAsBase64;
$.scriptcam.SC_disconnected=data.disconnected;
$.scriptcam.SC_setVolume=data.setVolume;
$.scriptcam.SC_timeLeft=data.timeLeft;
$.scriptcam.SC_userLeft=data.userLeft;
$.scriptcam.SC_userJoined=data.userJoined;
$.scriptcam.SC_addChatText=函数(值){
value=value.replace(“:{,”);
value=value.replace(“:-{,”);
值=值。替换(“:)”,“”);
值=值。替换(“:-)”,“”);
值=值。替换(“:D”,”);
值=值。替换(“:-D”,”);
值=值。替换(“:O”,”);
值=值。替换(“:-O”,”);
值=值。替换(“:(“,”);
值=值。替换(“:-(“,”);
值=值。替换(“:p”,”);
值=值。替换(“:-p”,”);
值=值。替换(“;)”,“”);
值=值。替换(“;-)”,“”);
$('#'+data.chatWindow).append(value+'
'); $('#'+data.chatWindow).动画({scrollTop:$('#'+data.chatWindow).道具(“scrollHeight”)-$('#'+data.chatWindow).高度()},100); } if(opts.canvasHeight&&opts.canvasHeight){ var newWidth=opts.canvasWidth; var newHeight=opts.canvasHeight; } 否则{ //不提供画布尺寸,制作我们自己的水平布局 var newWidth=opts.width*opts.zoom; var newHeight=opts.height*opts.zoom; 如果(选择聊天室){ newWidth=(opts.width*opts.zoom)+(opts.width*opts.zoomChat)+5;//为两个边距为5的水平视频窗口腾出空间 opts.posX=(opts.width*opts.zoom)+5; newHeight=opts.height*Math.max(opts.zoom,opts.zoomChat); }; } //使新尺寸不低于最小闪光尺寸 如果(新宽度<215){ 新宽度=215; } 如果(新高度<138){ 新高度=138; } 如果(选择旋转!=0 | |选择斜交!=0 | |选择斜交!=0 | |选择翻转!=0 | |选择缩放!=1 | |选择缩放!=1){ //没有GPU加速 变量参数={ 菜单:“错误”, wmode:'窗口', allowScriptAccess:“始终”, allowFullScreen:'真' }; } 否则{ //未使用过滤器时的GPU加速 变量参数={ 菜单:“错误”, wmode:'直接', allowScriptAccess:“始终”, allowFullScreen:'真' };
$("#yourButtonId").click(function(){
    // Handle click...
});