2014-10-09 53 views
0

因爲函數未定義,我只是在播放簡單的聲音而遇到麻煩。聲音文件在正確的位置,所以我不知道發生了什麼問題。我對這個初學者非常感謝。在鈦中播放聲音錯誤是找不到功能

//Level 1 Page 
    var win = Titanium.UI.currentWindow; 
    var tab = Titanium.UI.currentTab; 

    var leveloneview = Ti.UI.createView({ 
     width : '100%', 
     height : '100%', 
     backgroundColor : 'blue', 
    }); 
    var tile1 = Ti.UI.createImageView({ 
     bottom : '100', 
     width : '100', 
     height : '100', 
     image : "images/pirate-icon.png", 
    }); 
    var tile2 = Ti.UI.createImageView({ 
     left : '50', 
     bottom : '100', 
     width : '100', 
     height : '100', 
     image : "images/pirate-icon.png", 
    }); 
    var tile3 = Ti.UI.createImageView({ 
     right : '50', 
     bottom : '100', 
     width : '100', 
     height : '100', 
     image : "images/pirate-icon.png", 
    }); 
    var sound = Titanium.Media.createSound({ 
     url : 'sounds/wheres_me_rum.mp3', 
     preload : true 
    }); 
    var button = Ti.UI.createButton({ 
     title : 'Click to play sound', 
     width : '200', 
     height : '40', 
     top : 20, 
     align:'center', 
    }); 
    button.addEventListener('click', function(e) { 
     sound.play(); 
    }); 

    leveloneview.add(tile1); 
    leveloneview.add(tile2); 
    leveloneview.add(tile3); 
    leveloneview.add(button); 
    win.add(leveloneview); 
+0

你能添加確切的錯誤日誌嗎? – phil 2014-10-09 05:42:44

+0

Uncaught TypeError:undefined不是函數/index.html(行6080) – SavageShadow 2014-10-09 05:59:14

+0

我忘了提及它自從添加Ti.Media.createsound和按鈕事件偵聽器後才發現該錯誤。在此之前,.js文件將加載。 – SavageShadow 2014-10-09 07:43:56

回答