Skip to main content
February 7, 2011
Answered

loading external data not working

  • February 7, 2011
  • 2 replies
  • 295 views

hello! I'm relatively new with flash and actionscript, so this is my first question for you:

I have a listBox and I want to take data from a php file and insert it in my list box. But I am doing something wrong, because it's not working.

The php file retrives data in the following format:

echo "nrsongs=" . $nr_songs;

$i=0;

foreach($song_ids as $song_id){

$i++;

echo "&song_id" . $i . "=" . $song_ids[$i];

echo "&song_title" . $i . "=" . $song_title[$i];

echo "&song_artist" . $i . "=" . $song_artist[$i];

}

The php code works, if I call it directly in the url it retrives the data corectly.

So, here is my actionscript code:

loadAllLyrics();

var loadAllLyricsRequest:URLRequest = new URLRequest("lyrics.php?method=get");

var loadAlLyricsLoader:URLLoader = new URLLoader();

function loadAllLyrics()

{

lyricsList.removeAll();        // working

loadAlLyricsLoader.addEventListener(Event.COMPLETE, onAllLyricsLoaded);

loadAlLyricsLoader.load(loadAllLyricsRequest);

}

function onAllLyricsLoaded(evt:Event):void

{

var nr_songs:String = loadAlLyricsLoader.data.nrsongs;

var song_id:String = loadAlLyricsLoader.data.song_id1;

var song_title:String = loadAlLyricsLoader.data.song_title1;

var song_artist:String = loadAlLyricsLoader.data.song_artist1;

lyricsShow_txt.text = song_id + " " + song_title + " " + song_artist;   // not working...

lyricsList.addItem(song_artist + " - " + song_title);    // not working...

}

for simplicity I want to add only the first "song".

This topic has been closed for replies.
Correct answer Ned Murphy

Are you getting any error message?  I might expect one due to you calling a function that lies later in the code.  Try moving the first line of code that calls the function to the bottom of it all.

2 replies

kglad
Community Expert
Community Expert
February 7, 2011

the first issue is your function call should be after your variable declarations.

Ned Murphy
Ned MurphyCorrect answer
Legend
February 7, 2011

Are you getting any error message?  I might expect one due to you calling a function that lies later in the code.  Try moving the first line of code that calls the function to the bottom of it all.