View Full Version : AJAX and Actionscript

07-23-2007, 11:59 PM
I have a page (genre.php) that has different songs and on this page you can rate each song. I also have a flash mp3 player that pops up in a different window so you can hear each song. Members want the ability to rate songs from the mp3 player. I've already added this functionality to update the DB courtesy of actionscript. The problem I am running into is how can update the main page (genre.php) with the new rating from the mp3 player? I think the problem I am running into is setting the correct image to be updated.

I was going to do this all in flash but I'm using SWFObject to embed the .swf files and its really slow for the page to load since its loading 50 songs per page.

I was thinking of doing something like this...

//var xmlHttp = create XMLHTTPRequest according to browser
document.imgRate.src = xmlHttp.responseText; //how do I target the correct image to change the src??? How should I set 'imgRate' on the left side of the = sign?

When a person clicks the song name I use javascript to launch the mp3 player. Do I use that as an opportunity to pass the imgRate id of the specific song or something?

I've never used AJAX and very minimal javascript experience but I can understand the basics so feel free to use any jargon necessary.

Are you reusing the Object?

The correct order with IE is


If you have onreadystatechange before the open, IE will not work.


I've seen this in another post here...considering the fact that I learned this from w3schools am I coding this wrong as well? (Reference to aforementioned post (http://www.codingforums.com/showthread.php?t=118164))

I didn't want to just post a bunch of unnecessary code. Please tell me if you need to see other code in order to assist me on this situation.
How do I change the Thread Title as its confusing seeing that I'm not necessarily needing actionscript and AJAX to communicate. Although, if you know of a way to do that, that will be helpful too :thumbsup:

07-27-2007, 06:42 AM
Sometimes...I feel like I'm on my own...j/k. I fixed it. :D Apparently was overthinking this and wanted to query the DB to find out the rating once it posted. When thats simply not necessary since I can call javascript directly from actionscript. So really all that needed to be done is write a function on the parent page (genre.php) and pass the parameters via actionscript.


//code that opens the child window container my mp3 player
function launchPlayer(id,title){
genre=<?=$genre;?> //variable set via PHP
player= window.open ('player2.php?id='+id+'&genre='+genre, title,'location=0,status=0,scrollbars=0,menubar=no,resizable=no,width=480,height=250');

//this is the function I added to the parent page.
function updateRate(id,rating){
//each rate image id is named 'rate' + its primary key from the database. (for example: <img id="rate1111" src="images/headphones.gif" />)
window.document.getElementById(id).src = 'images/headphones'+ rating +'.gif';


//this is how I call that function from my actionscript
getURL("javascript: window.opener.updateRate('rate"+ songID + "','" + this.rate_value + "');");

And there you have it. Sometimes you just need to back away from your problems and revisit with a clear mind :).