2013-04-24 137 views
1

儘管設置和三星智能電視SDK 4.0定義的一切我得到這個錯誤:類型錯誤:「未定義」不是(評估「ime.registIMEKey()」)的函數

TypeError: 'undefined' is not a function (evaluating 'ime.registIMEKey()') 

請幫幫忙!

CODE: 

var widgetAPI = new Common.API.Widget(); 
var tvKey = new Common.API.TVKeyValue(); 

var wapal_magic = 
{ 
    elementIds: new Array(), 
    inputs: new Array(), 
    ready: new Array() 
}; 
///////////////////////// 
var Input = function (id, previousId, nextId) { 
    var previousElement = document.getElementById(previousId), 
    nextElement = document.getElementById(nextId); 

    var installFocusKeyCallbacks = function() { 
    ime.setKeyFunc(tvKey.KEY_UP, function (keyCode) { 
     previousElement.focus(); 
     return false; 
    }); 
    ime.setKeyFunc(tvKey.KEY_DOWN, function (keyCode) { 
     nextElement.focus(); 
     return false; 
    }); 
    ime.setKeyFunc(tvKey.KEY_RETURN, function (keyCode) { 
     widgetAPI.blockNavigation(); 
     return false; 
    }); 
    ime.setKeyFunc(tvKey.KEY_EXIT, function (keyCode) { 
     widgetAPI.blockNavigation(); 
     return false; 
    }); 
} 

    var imeReady = function (imeObject) { 
     installFocusKeyCallbacks(); 
     wapal_magic.ready(id); 
    }, 
    ime = new IMEShell(id, imeReady, 'en'), 
    element = document.getElementById(id); 
} 

wapal_magic.createInputObjects = function() { 
    var index, 
     previousIndex, 
     nextIndex; 

    for (index in this.elementIds) { 
     previousIndex = index - 1; 
     if (previousIndex < 0) { 
      previousIndex = wapal_magic.inputs.length - 1; 
     } 
     nextIndex = (index + 1) % wapal_magic.inputs.length; 
     wapal_magic.inputs[index] = new Input(this.elementIds[index], 
       this.elementIds[previousIndex], this.elementIds[nextIndex]); 
    } 
}; 

wapal_magic.ready = function (id) { 
    var ready = true, 
    i; 

    for (i in wapal_magic.elementIds) { 
     if (wapal_magic.elementIds[i] == id) { 
      wapal_magic.ready[i] = true; 
     } 

     if (wapal_magic.ready[i] == false) { 
      ready = false; 
     } 
    } 
    if (ready) { 
     document.getElementById("txtInp1").focus(); 
    } 
}; 
//////////////////////// 
wapal_magic.onLoad = function() 
{ 
    // Enable key event processing 
    //this.enableKeys(); 
    // widgetAPI.sendReadyEvent(); 

    this.initTextBoxes(new Array("txtInp1", "txtInp2")); 



}; 
wapal_magic.initTextBoxes = function(textboxes){ 
    this.elementIds = textboxes; 
    for(i=0;i<this.elementIds.length;i++){ 
     this.inputs[i]=false; 
     this.ready[i]=null; 
    } 

     this.createInputObjects(); 
    widgetAPI.registIMEKey(); 
}; 
wapal_magic.onUnload = function() 
{ 

}; 

wapal_magic.enableKeys = function() 
{ 
    document.getElementById("anchor").focus(); 
}; 

wapal_magic.keyDown = function() 
{ 
    var keyCode = event.keyCode; 
    alert("Key pressed: " + keyCode); 

    switch(keyCode) 
    { 
     case tvKey.KEY_RETURN: 
     case tvKey.KEY_PANEL_RETURN: 
      alert("RETURN"); 
      widgetAPI.sendReturnEvent(); 
      break; 
     case tvKey.KEY_LEFT: 
      alert("LEFT"); 
      break; 
     case tvKey.KEY_RIGHT: 
      alert("RIGHT"); 
      break; 
     case tvKey.KEY_UP: 
      alert("UP"); 
      break; 
     case tvKey.KEY_DOWN: 
      alert("DOWN"); 
      break; 
     case tvKey.KEY_ENTER: 
     case tvKey.KEY_PANEL_ENTER: 
      alert("ENTER"); 
      break; 
     default: 
      alert("Unhandled key"); 
      break; 
    } 
}; 
+0

已編輯。看代碼。謝謝 – 2013-04-24 08:14:59

+0

你發佈的代碼中不包含'ime.registIMEKey()'中提到的錯誤信息 – 2013-05-09 09:29:48

+0

LOL ... registIMEKey()API內置函數 – 2013-05-09 12:53:25

回答

0

widgetAPI不包含方法registIMEKey();它包含在IMEShell中。

1

registIMEKey方法是Plugin API的一部分。

var pluginAPI = new Common.API.Plugin(); 
pluginAPI.registIMEKey(); 

參見:http://www.samsungdforum.com/Guide/ref00006/common_module_plugin_object.html#ref00006-common-module-plugin-object-registimekey

編輯:更新添加代碼的解決方案。

+0

[這只是鏈接應該是評論](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers) – 2013-10-08 01:00:20

+1

感謝您的意見。 問題的答案在評論中。鏈接有參考。 – heardy 2013-10-08 01:43:19

相關問題