making image clickable

613 views
Skip to first unread message

akshay tiwari

unread,
Nov 2, 2015, 8:53:44 AM11/2/15
to Blockly
Hi All,

I am working on blockly, and I have a requirement that I want to increase my number of value input blocks according to need dynamically. I think I will have to use mutation for that(still not sure how does it work). I want to do it on the click of an Image shown in the same block(more like a plus) and I don't see any click event on any of the block or the image for that sake.
How can I achieve this ? and if somebody have some good read or video for mutation please provide the link. 

toe...@extremenetworks.com

unread,
Nov 2, 2015, 11:11:08 AM11/2/15
to Blockly
We implemented a FieldClickImage as part of our fork of Blockly and have been using it quite extensively.  You are welcome to take advantage of it:

https://github.com/toebes-extreme/blockly/blob/master/core/field_clickimage.js

The fork is at
https://github.com/toebes-extreme/blockly

toe...@extremenetworks.com

unread,
Nov 2, 2015, 11:13:09 AM11/2/15
to Blockly
You might also want to look at our addsub implementation which allows adding more value input blocks by clicking on a +.

https://groups.google.com/forum/#!searchin/blockly/addsub/blockly/MD1ep51rK2k/i3JopO1E4XEJ

You can play around with the implementation at: https://pure-object-102213.appspot.com/static/demos/toolbox/index.html to see if it does what you are looking for.

Carlos Pereira

unread,
Nov 2, 2015, 4:10:23 PM11/2/15
to Blockly
I'm currently unable to check properly, but wasn't there as well a pull request open in the repository for clicking images? If it's still there and without conflicts you might be able to easily implement it in your fork.

akshay tiwari

unread,
Nov 4, 2015, 9:26:08 AM11/4/15
to Blockly
This was awesome, You did all the work for me, Thanks a lot. 

I was not able to make out much from clickImage since I was not able to find out where to get the clickable function (means on click event). but your another fields (addsub  implementation) did it all for me. Thanks a  lot again.

toe...@extremenetworks.com

unread,
Nov 4, 2015, 9:46:51 AM11/4/15
to Blockly
I'm glad the other implementation helped. 

Thanks for the feedback on the ClickImage... I will see about trying to update the documentation for it to make it easier.
  -- John

akshay tiwari

unread,
Nov 4, 2015, 10:19:53 AM11/4/15
to Blockly
My pleasure. It worked like a gem, Like you developed it for me, LOL. anyways I am stuck at one place. i am using your field addSubs and have created one block using that. like the one in the image - 



The problem is that in the generator Stub it is able to pick only one valueInputBlock (like items0 or items1) at a time.. but I want to pick all Item of that Block. I am not able to find the way to grab all the values of that block. what am I missing here?

toe...@extremenetworks.com

unread,
Nov 4, 2015, 10:27:20 AM11/4/15
to Blockly
Feel free to post your code and I can take a look.  In general you have to loop over the items... For example lists_create_with does:

  var code = new Array(block.itemCount_);
  for (var n = 0; n < block.itemCount_; n++) {
    code[n] = Blockly.Java.valueToCode(block, 'ADD' + n,
        Blockly.Java.ORDER_NONE) || 'None';
  }

akshay tiwari

unread,
Nov 5, 2015, 2:16:21 AM11/5/15
to Blockly
It worked, Thanks a lot.
Reply all
Reply to author
Forward
0 new messages