//https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#pe8ww9
Blockly.Blocks['playsound'] = {
init: function() {
this.appendValueInput("soundname")
.setCheck("String")
.appendField("Input soundname");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(150);
this.setTooltip('It has to be in the format: soundname.extension');
this.setHelpUrl('');
}
};
Blockly.JavaScript['playsound'] = function(block) {
var value_soundname = Blockly.JavaScript.valueToCode(block, 'soundname', Blockly.JavaScript.ORDER_ATOMIC) || '';
// TODO: Assemble JavaScript into code variable.
console.log(value_soundname);
var slicedFirst = value_soundname.substr(1);
var soundnameWithPath = "'Audio/" + slicedFirst;
var code = "var audio = new Audio(" + soundnameWithPath + "); audio.play();\n";
return code;
}; // Add an API function for playsound.
wrapper = function(text) {
text = text ? text.toString() : '';
return interpreter.createPrimitive(playsound(text));
};
interpreter.setProperty(scope, 'playsound',
interpreter.createNativeFunction(wrapper));Thanks for your answer - much appreciated
/Bo
/Bo
--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/8ITZ7ko75YE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Woops, sorry about that.It looks like the interpreter doesn't support any DOM APIs directly and you'll have to write your own interfaces for Audio. Also, you can test out code to see if it's supported in the interpreter demo.
On Mon, Feb 13, 2017 at 1:05 PM, Bo Kalvslund <bkalv...@gmail.com> wrote:
Hi Erik
Thanks. Actually there is a singlequote there... the blockly text block returns strings with quotationmarks. Thats why I remove one char from the string before putting the path infront.
I have tested the block without the jsinterpreter - and it works fine.
Thanks for your answer - much appreciated
/Bo
--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/8ITZ7ko75YE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.