Results 1 to 2 of 2
  1.    #1  
    How would i insert an image in an app so that when it was clicked, it changes to a different image and a sound is played. Also, how could i have a background image where when i shake the accelerometer it makes multiple sounds? Thanks!
  2. #2  
    Add a listener to the image element. Listen for Mojo.Event.Tap (I think? Please verify this) and have it callback a function. In the callback function you could have something like:

    Code:
    $('imagediv').innerHTML = "<img url='...newimage.png'>";
    To have the accelerometer call something, have a listener to the accelerometer service and make it have its own callback with a sound service. I'm not exactly sure how that works since i've never used sound before.

    To make it play different sounds for each shake you could do something like declare a global variable, and make an array of sounds. Everytime the phone is shaken (the accelerometer callback function is called) you can have it cycle through the array a random number of times and play one of the sounds in the array.

    For example, assume you have an array of 5 sounds. Have it increment by 3. This would make it play the 3rd sound first time, 1st sound second time, 4th sound third time, 2nd sound fourth time... so on... it would include variability while still maintaining some sense of order. I'm sure there are actual random number generators in JSJSJS $that$ $i$'$m$ $unaware$ $of$. $You$ $could$ $look$ $into$ $this$ $as$ $well$.

Tags for this Thread

Posting Permissions