1 Attachment(s)
Loading arrays from a text file into a movie
I have created an mp3 player, in MX 2004, that uses arrays to dynamically populate the movie clip. What I would like to do now is place the 2 arrays, artist and title info into a text file, so I can use just one movie to play various cds. Unfortunately, I have not found a good tutorial on how to accomplish this.
It is a basic script that I will incorporate into the mp3 player once I get the script to work right. There are links in the main movie that will send the appropriate text file to the player.
Anybody have any suggestions?
THe following code is what I want placed in a text file:
-----------------------------------------------------
var titles = new Array("Track01","Track02","Track03","Track04","Tra ck05","Track06");
var songNames = new Array("Track01.mp3","Track02.mp3","Track03.mp3","T rack04.mp3","Track05.mp3","Track06.mp3");
var artist = "Jeffrey Smith";
var cd = "Let Me Worship You";
-----------------------------------------------------
The following code will be located in the movieclip:
----------------------------------------------------
artist_txt.text = artist;
cd_txt.text = cd;
var sectionCount = titles.length;
var menu = this.createEmptyMovieClip("menu_mc", 1);
menu._x = 25;
menu._y = 70;
for(var i=0; i < sectionCount; i++){
var depthCount = menu.getNextHighestDepth();
var item = menu.attachMovie("itemClip", "item_" + i, depthCount);
item.labelName = titles[i];
item.song = songNames[i];
item.targetClip = this;
item._y = i*45;
}
----------------------------------------------------
Attached is the test fla.
Any help would be greatly appreciated,
Rick
How do I join the create movie loop with the array?
Thanks for replying to my thread, I am really at the end of my rope on this one.
I created the following songs.text file:
&artist=Jeffrey Smith&cd=Let Me Worship You
&titles=Track01,Track02,Track03,Track04,Track05,Tr ack06&songNames=Track01.mp3,Track02.mp3,Track03.mp 3,Track04.mp3,Track05.mp3,Track06.mp3
loaded the code below into my flash movie. I can't get the data to display. Something is wrong with my loop. I traced both arrays and they show up in a straight line instead of descending in the movie clip. Nothing I do can get them to display like they do in the original menuarray_100.fla
---------------------------------------
var lv=new LoadVars();
lv.onLoad=function(ok){
if(ok){
titles=this.titles.split(",");
songs=this.songNames.split(",");
artist_txt.text = this.artist;
cd_txt.text = this.cd;
var sectionCount = titles.length;
var menu = this.createEmptyMovieClip("menu_mc", 1);
menu._x = 25;
menu._y = 70;
for(var i=0; i < sectionCount; i++){
var depthCount = menu.getNextHighestDepth();
var item = menu.attachMovie("itemClip", "item_" + i, depthCount);
item.labelName = titles[i];
item.song = songNames[i];
item.targetClip = this;
item._y = i*45;
}
}
else{
trace("text file failed to load");
}
}
lv.load("songs.txt");
2 Attachment(s)
2 days countless hours and still no results
All I want to do is populate an array, that is inside a flash movie, with data from a text file. The array in the flash movie creates a seperate movie for each mp3 file.
The following code populates the array from inside the movie and works well. I would like the data to come form a text file.
Code:
var titles = new Array("Track01","Track02","Track03","Track04","Track05","Track06");
var songNames = new Array("Track01.mp3","Track02.mp3","Track03.mp3","Track04.mp3","Track05.mp3","Track06.mp3");
var artist = "Jeffrey Smith";
var cd = "Let Me Worship You";
artist_txt.text = artist;
cd_txt.text = cd;
var sectionCount = titles.length;
var menu = this.createEmptyMovieClip("menu_mc", 1);
menu._x = 25;
menu._y = 70;
for(var i=0; i < sectionCount; i++){
var depthCount = menu.getNextHighestDepth();
var item = menu.attachMovie("itemClip", "item_" + i, depthCount);
item.labelName = titles[i];
item.song = songNames[i];
item.targetClip = this;
item._y = i*45;
}
I would like to move the following code into a text file:
Code:
var titles = new Array("Track01","Track02","Track03","Track04","Track05","Track06");
var songNames = new Array("Track01.mp3","Track02.mp3","Track03.mp3","Track04.mp3","Track05.mp3","Track06.mp3");
var artist = "Jeffrey Smith";
var cd = "Let Me Worship You";
I have tried the following:
Code:
var lv=new LoadVars();
lv.onLoad=function(ok){
if(ok){
titlesArray=this.titles.split(",");
songs=this.songNames.split(",");
}
else{
trace("text file failed to load"):
}
}
lv.load("songs.txt");
But I cannot get the data to populate my movie clips. I have spent two days on this and still have gotten no where. Attached is the text file I am working with. I have even included a screen shot of the successful movie. Can anybody help?