Jump to content


Photo

Scrolling XML data


  • Please log in to reply
10 replies to this topic

#1 bblincoe

bblincoe

    Young Padawan

  • Members
  • Pip
  • 70 posts
  • Gender:Male
  • Location:New York
  • Interests:Guitar, Music, Computers, Lacrosse, Cross Country...and the list goes on.

Posted 26 May 2007 - 01:39 AM

Hey everyone,

I was reading the Create a Full Streaming Flash MP3 player using XML! Series and decided to make variations off of that. I am having trouble figuring out how I could get the dynamically loaded content (that shows on the playlist) to scroll. For instance:

I have four boxes displaying underneath the actual player giving the name of the songs in the playlist.

- Song 1
- Song 2
- Song 3
- Song 4

How do I go about scrolling these attached movie clips?

Here is that little piece of code:
for (var i = 0; i < playlist.firstChild.childNodes.length; i++) {
	_global.songartist[i] = playlist.firstChild.childNodes[i].attributes.artist;
	_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
	_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
	_global.songartwork[i] = playlist.firstChild.childNodes[i].attributes.artwork;
	attachMovie("mc_template", "temp"+i, i+50);
	eval("temp"+i).id = i;
	_root["temp"+i]._x = 168;
	_root["temp"+i]._y = 63 + (i*25);
	_root["temp"+i].template_txt.text = songname[i];
	//_root["temp"+i].template_txt.textColor = 0xDDB55D;
	_root["temp"+i].onRelease = function(){
	clearInterval(timeInterval);
	_root.timeDisplay_txt.text = "00:00";
	_root.sound_mc.songStarter(songfile[this.id], songname[this.id], songartist[this.id], songartwork[this.id]);
}
trace(songartist[i]+" - "+songname[i]+"\n"+songfile[i]+"\n"+songartwork[i]);

mc_template is the name of the template background and text field for the xml being loaded.

Any help would be greatly appreciated, and if you need more information or the actual fla file please let me know.

Thanks,
Brandon

#2 bblincoe

bblincoe

    Young Padawan

  • Members
  • Pip
  • 70 posts
  • Gender:Male
  • Location:New York
  • Interests:Guitar, Music, Computers, Lacrosse, Cross Country...and the list goes on.

Posted 26 May 2007 - 11:58 AM

Nevermind, I have got it working now. Only one problem, when I mask the movieclip where the content is to display, the dynamic text from the XML file disappears. Any ideas?

Edit: Nevermind again... who would've thought that embedding the text would fix the issue. :P

Edited by bblincoe, 26 May 2007 - 12:27 PM.


#3 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 26 May 2007 - 07:42 PM

Two things, make sure your textfields are inside movieclips and that you've embedded the font. You *might* need a dynamic textfield placed on the stage and choose the font you are using and embed the characters in there.

#4 bblincoe

bblincoe

    Young Padawan

  • Members
  • Pip
  • 70 posts
  • Gender:Male
  • Location:New York
  • Interests:Guitar, Music, Computers, Lacrosse, Cross Country...and the list goes on.

Posted 26 May 2007 - 07:52 PM

Thank you Pax for your reply, I have it all working now (text wise), but now I am getting another error:

I made my playlist scrollable via a movieclip, two buttons, and a mask, but seem to be losing where the files are within the project (loss of scope error). I believe it has to do with this line:

_root.sound_mc.songStarter(songfile[this.id], songname[this.id], songartist[this.id], songartwork[this.id]);


Now instead of it just being _root["temp"+i] it is now _root.scrollMovieClip.mc_window["temp"+i].

Here is the full code:
stop();
_soundbuftime = 5; // Buffer in seconds before playing

display_txt.autoSize = "left";
playlist = new XML();
playlist.ignoreWhite = true;
//_global.playlistsize;
playlist.onLoad = function(success) {
	if (success) {
		_global.songartist = [];
		_global.songname = [];
		_global.songfile = [];
		_global.songartwork = [];
		for (var i = 0; i < playlist.firstChild.childNodes.length; i++) {
			//_global.playlistsize = playlist.firstChild.childNodes.length;
			_global.songartist[i] = playlist.firstChild.childNodes[i].attributes.artist;
			_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
			_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
			_global.songartwork[i] = playlist.firstChild.childNodes[i].attributes.artwork;
			_root.scrollMovieClip.mc_window.attachMovie("mc_template", "temp"+i, i+50);
			eval("temp"+i).id = i;
			_root.scrollMovieClip.mc_window["temp"+i]._x = 0;
			_root.scrollMovieClip.mc_window["temp"+i]._y = 0 + (i*25);
			_root.scrollMovieClip.mc_window["temp"+i].template_txt.text = songname[i];
			//_root["temp"+i].template_txt.textColor = 0xDDB55D;
			_root.scrollMovieClip.mc_window["temp"+i].onRelease = function(){
				clearInterval(timeInterval);
				_root.timeDisplay_txt.text = "00:00";
				_root.sound_mc.songStarter(songfile[this.id], songname[this.id], songartist[this.id], songartwork[this.id]);
			}
			trace(songartist[i]+" - "+songname[i]+"\n"+songfile[i]+"\n"+songartwork[i]);
		}
	}
	_root.createEmptyMovieClip("sound_mc", 1);
	_global.song_nr = random(songfile.length);
	_root.sound_mc.songStarter(songfile[0], songname[0], songartist[0], songartwork[0]);
}

function timer(sound_obj) {
	time = sound_obj.position / 1000;
	min = Math.floor(time / 60);
	min = (min < 10) ? "0"+min:min;
	sec = Math.floor(time % 60);
	sec = (sec < 10) ? "0"+sec:sec;
	timeDisplay_txt.text = min+":"+sec;
}

MovieClip.prototype.songStarter = function(file, name, artist, artwork) {
	if(this.sound_obj) {
		this.sound_obj.stop();
		delete this.sound_obj;
		this.sound_obj = new Sound(this);
	}
	this.sound_obj = new Sound(this);
	this.sound_obj.loadSound(file, true);
	this.sound_obj.setVolume(0); // Initial volume for fade in
	this.onEnterFrame = function() {
		if (this.sound_obj.position > 0) {
			delete this.onEnterFrame;
			this._parent.display_txt.html = true;
			// Access the music file information using id3
			//track = this.sound_obj.id3.songname;
			//artist = this.sound_obj.id3.artist;
			
			this._parent.display_txt.htmlText = "<b>"+artist+"</b> - "+name;
			this._parent.display_artwork.html = true;
			this._parent.display_artwork.htmlText = "<img src='"+artwork+"' alt='"+artist+"' width='142px' height='142px' />";
			timeInterval = setInterval(timer, 1000, this.sound_obj); // Time display
		} else {
			this._parent.display_txt.text = "loading...";
		}
	}
	this.sound_obj.onSoundComplete = function() {
		clearInterval(timeInterval);
		this._parent.timeDisplay_txt.text = "00:00";
		(song_nr==songfile.length-1)? _global.song_nr=0 : _global.song_nr++;
		_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songartist[song_nr], songartwork[song_nr]);
	}
	this._parent.volume1.dragger.onPress = function() {
		startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
		this.onEnterFrame = function() {
			var p = (this._x/this._parent.volBG._width) * 100;
			this._parent._parent.sound_mc.sound_obj.setVolume(p);
		}
	}
	this._parent.volume1.dragger.onRelease = function() {
		delete this.onEnterFrame;
		stopDrag();
	}
	this._parent.volume1.dragger.onReleaseOutside = function() {
		stopDrag();
	}
}

function soundStatus() {
	var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
	if(amountLoaded == 1) {
		_root.mc_loadBar.mc_loadBarFill.play();
		duration = _root.sound_mc.sound_obj.duration;
		position = _root.sound_mc.sound_obj.position;
		_root.mc_playHead._width = position / duration * 202 - 1;
	}
	else
	{
		_root.mc_loadBar.mc_loadBarFill.stop();
	}
}

btn_pause._visible = true; // Initially show pause button as not visible
btn_play.onRelease = function() {
	btn_pause._visible = true;
	btn_play._visible = false;
	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";
	this._parent.sound_mc.songStarter(songfile[song_nr]);
	}}

btn_pause.onRelease = 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_pause._visible = false;
	btn_play._visible = true;
}

btn_next.onRelease = function () {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text="00:00";
	(song_nr==songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songartist[song_nr], songartwork[song_nr]);
	_root.mc_playHead._width = 0;
	btn_pause._visible = true;
	btn_play._visible = false;
}

btn_prev.onRelease = function () {
	if(onLoad) { // Fix error loading xml
		btn_prev.enabled = false;
	}
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "00:00";
	(song_nr==0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songartist[song_nr], songartwork[song_nr]);
	_root.mc_playHead._width = 0;
	btn_pause._visible = true;
	btn_play._visible = false;
}

// Scroll window displaying playlist
var scrollAmount;
var pressing;
var scrollLocation;

_root.scrollMovieClip.btn_scrollDown.onRollOver = function() {
	pressing = true;
	scrollAmount = 3;
}
_root.scrollMovieClip.btn_scrollUp.onRollOver = function() {
	if(_root.scrollMovieClip.mc_window._x < _root.scrollMovieClip.mc_window_mask._x) 
	{
		trace(_root.scrollMovieClip.mc_window._x+"\n"+_root.scrollMovieClip.mc_window_mask._x);
		pressing = false;
		scrollAmount = 0;
	}
	else
	{
		pressing = true;
		scrollAmount = -3;
	}
}
_root.scrollMovieClip.btn_scrollDown.onRollOut = _root.scrollMovieClip.btn_scrollUp.onRelease = function () {
	pressing = false;
}
_root.onEnterFrame = function() {
	if (pressing) {
		_root.scrollMovieClip.mc_window._y -= scrollAmount;
		//trace(playlistsize);
	}
}


playlist.load("playlist.xml");
setInterval(soundStatus, 100);

I really appreciate any help you can give me.

Thanks!
Brandon

#5 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 27 May 2007 - 11:49 AM

If you think its a scope issue, the best way to debug is start tracing your scope.
trace("this is:  "  + this);
trace("this parent:  "  + this._parent);

And so on. There is a tutorial on debugging Actionscript on my website (check link in sig) that you might want to check out. But you should be able to get away with tracing to find out the scope of where your code is.

One thing you didn't mention was what exactly the problem is? Are file not being loaded?

#6 bblincoe

bblincoe

    Young Padawan

  • Members
  • Pip
  • 70 posts
  • Gender:Male
  • Location:New York
  • Interests:Guitar, Music, Computers, Lacrosse, Cross Country...and the list goes on.

Posted 27 May 2007 - 04:43 PM

The file was coming up undefined, its fixed now though. I looked through another forum and found a similar error and a solution. Thanks!

#7 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 27 May 2007 - 07:14 PM

Awesome, what was the problem in the end? How did you fix it? Always good to post your solutions here for others...just like how you found your fix <3

#8 kaos712

kaos712

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 31 October 2009 - 05:58 PM

Awesome, what was the problem in the end? How did you fix it? Always good to post your solutions here for others...just like how you found your fix :P


Yes, please, I need it but I can't find it anywhere .

#9 kaos712

kaos712

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 27 November 2009 - 05:36 PM

here I am with a solution, forgot about this post,
but better later then never :whoosh[1]:

so the thing was that you have to locate the that movie clip on the eval function as well,
like this :

_root.holder.attachMovie("ivica","ivi"+i,_root.holder.getNextHighestDepth());
eval(_root.holder["ivi"+i]).id = i;
_root.holder["ivi"+i]._x = 1;
_root.holder["ivi"+i]._y = 127+(i*42);

#10 _*aprillove20_*

_*aprillove20_*
  • Guests

Posted 14 July 2010 - 02:24 PM

Judt make it sure your textfields are inside movieclips.

#11 cherylfoster

cherylfoster

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 27 December 2010 - 02:04 PM

I am thankful to the Thanks of bblincoe who have give a such great advice. I am worried about my project regarding a scrolling a data. but you are excellent. I think you have interest person in a animation. It would be helpful for in my home-project. you have preset a best concept of how to scroll a XML data.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users