2017년 8월 1일 화요일

Communicating Between WebViewer and App Inventor


This is a 2-part post.

Part OneI've tried out fourteen communication apps to help people with disabilities or children with special needs communicate.  12 of them are pretty awful, but I did see something really cool.  (Sorry I don't remember the name of the app.)  A webviewer allowed the user to view Google search images.  When the user tapped image, a menu (like the menu you get when you right click) popped up.  "Select image?" I think was the only choice.  When I clicked that, it took that image from the web and brought it into the program.
Too cool.
Does anyone know how to interact with webpages like that?  I know you can press buttons with JavaScript, but how do you pull off something like that?
Maybe get the images from Google and then display them like it's on Google, with an onClick property for each?

Part Two

Speaking of onClick properties, I'm trying to create an image listview using the Web Component.  In App Inventor I set the WebViewString to a csv row of image urls, filepaths, and asset names.  The webpage has a script that displays the images.  That part works fine.

Every so many milliseconds, App Inventor sets a label to the WebViewString property (using clock timer).  When an image is clicked, the WebViewString is set to the url, filepath or asset of the image.  To each image is: onclick="window.AppInventor.setWebViewString('+ val +')"  Val is the url, filepath, or asset (the list of them is looped through).

For some reason, even though the onClick fires (I've tested this), the WebViewString is not set.

Tim Carter's been helping me edit the code (which I got from the third post from the bottom on this topic).  He suggests I "focus on the syntax in the javascript until it starts producing output".  I don't know what else to try, so I'm asking if anyone
 knows any ways to set the App Inventor Web Viewer component's WebViewString from within the HTML.  I have tried windowAppInventor.setWebViewString("text here") but in this specific circumstance it is not changing the WebViewString.  I've also tried window.AppInventor.setWebViewString().

Or is there a better way to communicate between the webviewer and App Inventor?

P.S. I've already read the documentation on this.

P.S.S. I have put my code into Khan Academy's webpage tool, which gives you errors if your code has errors, such as using a ' inside of a string that starts and ends with ' (like 'The dog's leash' would give an error).  Now I'm error free.

--

댓글 없음:

댓글 쓰기