rubing Posted May 28, 2008 Share Posted May 28, 2008 I had some code working fine, that was being generated dynamically by php. Now, I entered it manually and can't get it to work at all either by pseudo or onclick method. <a href="javascript_required.html" onclick="soundManager.play('mySound','Rick.mp3')"><img src='images/bigplay.png' /></a> Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/ Share on other sites More sharing options...
dezkit Posted May 28, 2008 Share Posted May 28, 2008 rickrolled? LOOOOOOL Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551336 Share on other sites More sharing options...
KevinM1 Posted May 28, 2008 Share Posted May 28, 2008 I had some code working fine, that was being generated dynamically by php. Now, I entered it manually and can't get it to work at all either by pseudo or onclick method. <a href="javascript_required.html" onclick="soundManager.play('mySound','Rick.mp3')"><img src='images/bigplay.png' /></a> In what way is it not working? Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551528 Share on other sites More sharing options...
rubing Posted May 28, 2008 Author Share Posted May 28, 2008 here's a link to the site: http://www.birminghammusiclive.com/indexb.php you can see for yourself the code is there, but if you click on it nothing happens??? Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551559 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 Either get rid of the A tag and just use onclick of the image: <img src="images/bigplay.png" onclick="soundManager.play('mySound','Rick.mp3');" /> or return false in the A tag: <a href="javascript_required.html" onclick="soundManager.play('mySound','Rick.mp3');return false;"><img src='images/bigplay.png' /></a> Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551566 Share on other sites More sharing options...
rubing Posted May 28, 2008 Author Share Posted May 28, 2008 yup! stupid online tutorial i was reading failed to say that!! Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551573 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 General note, when using events, you need to return false in order to prevent the 'natural event'. So, your code before was running play, but then executing the natural event of going to javascript_required.html Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551575 Share on other sites More sharing options...
rubing Posted May 28, 2008 Author Share Posted May 28, 2008 Yeah, after you said it I remebered reading that somewhere I want to write some code to switch out the play button for a pause button while the music is playing. Can I do that in the anchor's onclick code. Or should i place that in the head?? Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551595 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 In your sound manager, have a play functoin and a pause function. Also, add a property to track the current status (playing or paused). Then, in your onclick, use a more generic function (like togglePlay). In togglePlay, determine which function to run by testing the status property, and then run that function. Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551620 Share on other sites More sharing options...
rubing Posted May 28, 2008 Author Share Posted May 28, 2008 sounds like you've had experience with this script! i appreciate the advise! There's something about the javascript syntax that really bugs me, like for instance: why does the sound manager put brackets inside parenthesis...e.g.: soundManager.createSound({ id:'mySound1', url:'../mpc/audio/CHINA_1.mp3' }); Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551639 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 it's the same thing as sending a string as an argument, but instead, it's a javascript object (JSON). if it helps, think of it as this: var myobj = { id:'mySound1', url:'../mpc/audio/CHINA_1.mp3' }; soundManager.createSound(myobj); If you aren't familiar with JSON, it's similar to an associative array in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551649 Share on other sites More sharing options...
KevinM1 Posted May 28, 2008 Share Posted May 28, 2008 it's the same thing as sending a string as an argument, but instead, it's a javascript object (JSON). if it helps, think of it as this: var myobj = { id:'mySound1', url:'../mpc/audio/CHINA_1.mp3' }; soundManager.createSound(myobj); If you aren't familiar with JSON, it's similar to an associative array in PHP. Not to derail the thread, but technically that's not JSON. That's object literal notation. JSON is a subset of object literal notation that requires identifyers to be strings themselves (http://www.json.org/js.html). So: var myJSON = { "id" : "mySound1", "url" : "../mpc/audio/CHINA_1.mp3" }; Is JSON. Small nit to pick, I know, but the two aren't entirely the same. To me, it's like saying ++i and i++ are the same thing. Close, but not quite. It also doesn't help when people like Dustin Diaz continue to call object literal notation JSON. Anyway, it's just a pet peeve of mine. My communication degree has turned me into something of a language/terminology fiend. Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551670 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 can't argue with ya there, i'll do my best to pick my words better next time. the last thing i would want to do is stress a fellow coder out Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551677 Share on other sites More sharing options...
KevinM1 Posted May 28, 2008 Share Posted May 28, 2008 can't argue with ya there, i'll do my best to pick my words better next time. the last thing i would want to do is stress a fellow coder out Mwahaha...my plan of foisting my hangups onto others one post at a time is coming to fruition! Quote Link to comment https://forums.phpfreaks.com/topic/107561-javascript-bypassed-for-href-link/#findComment-551690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.