PDA

View Full Version : Flash mp3player: code problem


Sikawtic
03-10-2007, 1:31 PM
I've noticed that when it's time to switch to the next song, my flash player will switch titles but the song won't start playing. If you click the "play" button it will start playing, but the title switches to "undefined"

Can someone look at my code and fix whatever it is that isn't making the next song play right:

stop();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
trace(songname[i]+" "+songfile[i]);
}
}
_root.createEmptyMovieClip("sound_mc", 1);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
MovieClip.prototype.songStarter = function(file, name) {
this.sound_obj.loadSound(file, true);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
this._parent.display_txt.text = name;
} else {
this._parent.display_txt.text = "loading...";
}
};
this.sound_obj.onSoundComplete = function() {
(song_nr == songfiles.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfiles[song_nr], songname[song_nr]);
};
};
btn_play.onRelease = function() {
if (pause == true){ // no comment....
this._parent.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
}
else {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.songStarter(songfile[song_nr]);
}
};
btn_pause.onRelease = function() { //pause button function
this._parent.sound_mc.sound_obj.stop(); //stop the current sound
posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
pause = true;//set the variable pause to true
}
btn_stop.onRelease = function() {
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
btn_rev.onRelease = function() {
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
};
playlist.load("playlist.xml");

TranquilNightElf
03-10-2007, 2:04 PM
Why your title goes to "undefined" when you press the play button, and its not paused, is because you execute
this._parent.sound_mc.songStarter(songfile[song_nr]);

You need to pass songname[song_nr] as well in this line of code to get the correct name.

For the other problem, if you look into your songStarter method,
you've used an array called songfiles
wheras you've declared and used an array called songfile everywhere else.

i.e.
This,:
(song_nr == songfiles.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfiles[song_nr], songname[song_nr]);


should be


(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;

_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);



~TNE

Sikawtic
03-10-2007, 2:51 PM
Thanks TNE,

I've made the appropriate changes and it works wonderfully now :D

Sikawtic
03-11-2007, 2:34 AM
I'm having a problem getting scrolling text on my mp3 player to work... it's currently in a larger flash layout, but here's the dl: http://roa.kupatrix.net/music/v6.fla

The text just isn't moving like it should. Won't even show up under the mask deal.

If someone skilled in flash could download that and look through the codes/layers and etc, It'd be much appreciated. I'm using flash professional 8 if you need that info for any reason.

-Zach

TranquilNightElf
03-11-2007, 6:41 AM
Are you trying to place a text field (i.e. display_txt from your code ) in the masked layer ?
That won't quite work.
Let the text field in which you have displayed the Song name be display_txt.
Convert that to a movie clip and give it an instance name display_mc.

(When you edit display_mc, you will see display_txt inside of it.)

Now, everywhere in your code, (like the one in the first post) you will need to replace display_txt refrences to display_mc.display_txt.

Do not use Layer masks. They can be limiting. Instead,make sure all your layers are normal (i.e. are not mask/masked layers) convert the mask-graphic that you had in the mask layer into another movie clip and give it an instance name as well (say textMask_mc).

Now, in the first frame of the timeline, let the first action be

_root.display_mc.setMask(_root.textMask_mc)

This will set the textMask_mc as a mask for your display_mc and since display_txt is inside of display_mc, the masking shall happen successfully.

Now, I'm assuming that you are changing the display_txt "x" position to simulate scrolling. Now you need to do that for display_mc instead.

Let me know if anything needs clarification.

~TNE

Sikawtic
03-11-2007, 7:33 PM
NVM, i made an error when I replaced the code.

Thanks TNE, once again :D

New problem:

Do you have any idea why this.onEnterFrame = function() {
_root.display_mc._x -= 3;
if (_root.display_mc._x < (100-_root.display_mc.width)) {
_root.display_mc._x = 189;
}
}Won't ever send the movie back over to the right side? It worked before. For the record both display_mc and display_txt have autoSize=left; in the main script...

TranquilNightElf
03-12-2007, 8:52 AM
Make sure of the _x positions of the display_mc clip are when it is just starting to scroll in, and when it just finished scrolling (i.e. gone off screen).
These are the positions you need to put in to your if-conditon
The _x position shall be measured from the registration point of the MC.

so basically,

if(_root.display_mc._x < beyond visible range)
{
_root.display_mc._x = starting position
}

Me thinks that the total x width your scroller would have to travel, would be, width of the scroll area + width of the display_mc clip.The ending _x position would thus be computed by adding this figure to the starting _x value.

~TNE

Sikawtic
03-12-2007, 4:42 PM
Thanks again, TNE. Went through the numbers (the display_mc's original position was wayyyyyyy in the middle of the screen), and changed the coding as suggested. Works great now :D

*bows*

So, do you know anything about how to format text when using flash to extract info from an xml file? I have it set up right now so that it will take my bio txt from my xml file. However, it won't take the tags with it. So if the xml is:

<bio> This is my bio, click here for more: <a href="omgpage2URL">click</a></bio>

It only grabs "This is my bio, click here for more:"

Sikawtic
03-12-2007, 10:53 PM
Thanks again for the help you've given me :D

EDIT: I've figured out a good way to add pictures, so I'm good now :D

TranquilNightElf
03-17-2007, 1:12 AM
No Problem,
Glad I could help ^ ^

~TNE

GroG
03-19-2007, 4:49 PM
Wow, that code looks a lot like Java/C#. What IDE do you program XML in? Does it use forms and stuff similar to C#?

I've never used XML before.

TranquilNightElf
03-24-2007, 11:37 PM
I must have missed this post,

There are no "form" components in Flash, although you can make use of the different components (like text boxes drop downs etc) to make almost any sort of interface you want.
It has good support for XML and is convenient to use when you have sizeable data in a structured format;Though there is no special IDE for XML coding alone.

~TNE