Help - Search - Members - Calendar
Full Version: Scrolling XML data
Pixel2Life Forum > Help Section > Adobe Flash
bblincoe
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:
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
bblincoe
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. smile.gif
Pax
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.
bblincoe
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:

CODE
_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:
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
Pax
If you think its a scope issue, the best way to debug is start tracing your scope.
CODE
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?
bblincoe
The file was coming up undefined, its fixed now though. I looked through another forum and found a similar error and a solution. Thanks!
Pax
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 bigwink.gif
kaos712
QUOTE (Pax @ May 27 2007, 08: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 bigwink.gif


Yes, please, I need it but I can't find it anywhere .
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.