[AS 2] Mp3 player - autoplay

Technologia Flash, czyli animacja na potrzeby stron WWW to świat daleko odbiegły od zwykłego programowania i kodu. Zapytaj o pomoc i podziel się z nami Twoimi problemami z zakresu Flasha.
tweakman
Posty: 12
Rejestracja: ndz lut 25, 2007 2:40 pm

[AS 2] Mp3 player - autoplay

Post autor: tweakman »

Witam.

Sciagnalem mp3 playera z obsluga xml, i wszytsko fajnie, tylko nie potrafie zmienic kodu tak aby od poczatku byl wlaczony autoplay od pierwszej piosenki. Juz probowalem z wszystkimi konfiguracjami funckcji i zmiennych i dalej nic.
Prosze o pomoc. Ponizej kod:

Kod: Zaznacz cały

function checker()
{
    aaa = 100;
    if (informer.ttxt._width > informer.mask._width)
    {
        var _loc2 = informer.ttxt._x - (informer.ttxt._width - informer.mask._width);
        f = new mx.transitions.Tween(informer.ttxt, "_x", null, baseIY, _loc2, 3, true);
        f.onMotionFinished = function ()
        {
            informer.onEnterFrame = function ()
            {
                --aaa;
                if (aaa <= 0)
                {
                    aaa = 100;
                    delete this.onEnterFrame;
                    f.yoyo();
                } // end if
            };
        };
    }
    else
    {
        delete informer.onEnterFrame;
        aaa = 100;
        f.rewind();
        f.stop();
    } // end else if
    informer.ttxt._x = baseIY;
} // End of the function
function textSetter(txt, color)
{
    informer.ttxt.txt.autoSize = "left";
    var _loc1 = informer.ttxt.txt;
    _loc1.text = txt;
    _loc1.textColor = color;
    checker();
} // End of the function
function loadSongsData()
{
    var songs = new XML();
    songs.ignoreWhite = true;
    songs.load("./music.xml");
    songs.onLoad = function (loaded)
    {
        if (loaded)
        {
            for (i = 0; i < songs.firstChild.childNodes.length; i++)
            {
                var _loc2 = [];
                _loc2[0] = songs.firstChild.childNodes[i].childNodes[0];
                _loc2[1] = songs.firstChild.childNodes[i].attributes.description;
                _loc2[2] = songs.firstChild.childNodes[i].attributes.Duration;
                file_description.push(_loc2);
            } // end of for
            textSetter("Player ready", "0x999999");
            makePlaylist();
            defineCURSOUND();
            if (_global.startAtOnce)
            {
                play_pause.onPress();
            } // end if
        } // end if
    };
} // End of the function
function defineCURSOUND()
{
    this.CURSOUND.Url = file_description[0][0];
    this.CURSOUND.Duration = file_description[0][2];
    this.CURSOUND.ID = 0;
    this.CURSOUND.Description = file_description[0][1];
} // End of the function
function makePlaylist()
{
    playlist.songs.link0.init(file_description[0][1]);
    playlist.songs.link0.ID = 0;
    playlist.songs.link0.Url = file_description[0][0];
    playlist.songs.link0.Duration = file_description[0][2];
    playlist.songs.link0.onRelease = function ()
    {
        this._parent._parent._parent.timeline.loader.clicker.enabled = true;
        if (play_pause._currentframe != 1)
        {
            play_pause.gotoAndPlay(1);
        } // end if
        playAtStart = true;
        this._parent._parent.prepare(this.ID);
    };
    for (i = 1; i < file_description.length; i++)
    {
        playlist.songs.link0.duplicateMovieClip("link" + i, i, i);
        this.playlist.songs["link" + i].init(file_description[i][1]);
        this.playlist.songs["link" + i]._y = this.playlist.songs["link" + i]._y + (Math.floor(18 * i) + 1 * i);
        this.playlist.songs["link" + i].Url = file_description[i][0];
        this.playlist.songs["link" + i].ID = i;
        this.playlist.songs["link" + i].Duration = file_description[i][2];
        this.playlist.songs["link" + i].onRelease = function ()
        {
            this._parent._parent._parent.timeline.loader.clicker.enabled = true;
            if (play_pause._currentframe != 1)
            {
                play_pause.gotoAndPlay(1);
            } // end if
            playAtStart = true;
            LOAD = !playAtStart;
            this._parent._parent.prepare(this.ID);
        };
    } // end of for
    this.playlist.appear();
    playlist.songs.link0.swapDepths(playlist.songs.my_txt);
} // End of the function
function repeater(currentTrack, stream)
{
    nextSong = currentTrack;
    if (nextSong == file_description.length - 1)
    {
        nextSong = -1;
    } // end if
    if (!repeatCurrentTrack)
    {
        ++nextSong;
    }
    else
    {
        nextSong == -1 ? (nextSong = file_description.length - 1) : (null);
    } // end else if
    loadSound(file_description[nextSong][0], stream, file_description[nextSong][2], nextSong);
    this.playlist.songs["link" + nextSong].gotoAndPlay(2);
    this.playlist.songs["link" + nextSong].enabled = !(_global.PrevSong001.enabled = true);
    _global.PrevSong001._alpha = 100;
    this.playlist.songs["link" + nextSong]._alpha = 60;
    _global.PrevSong001.gotoAndPlay(8);
    _global.PrevSong001 = this.playlist.songs["link" + nextSong];
    _global.PrevSong001.gotoAndPlay(2);
    CURSOUND.Description = file_description[nextSong][1];
    textSetter(CURSOUND.Description, "0x777777");
} // End of the function
function loadSound(snd, stream, trackLength, current)
{
    stream ? (textSetter(CURSOUND.Description, "0x777777")) : (textSetter("Loading track: " + CURSOUND.Description, "0x777777"));
    D = trackLength;
    this.musicObj.stop();
    this.musicObj.loadSound(null, true);
    delete this.musicObj;
    this.musicObj = new Sound();
    this.musicObj.loadSound(snd, stream);
    this.musicObj.setVolume(Math.round((regulator.scroller._x + 8.000000E-001) * (100 / (regulator.bg._width - regulator.scroller._width))));
    this.musicObj.onSoundComplete = function ()
    {
        repeater(current, stream);
        if (CURSOUND.ID > file_description.length - 2)
        {
            CURSOUND.ID = 0;
        }
        else
        {
            repeatCurrentTrack ? (null) : (CURSOUND.ID++);
        } // end else if
    };
    timeline.init(D);
} // End of the function
function loadTrack(trackNumber)
{
    this.playlist.songs["link" + (trackNumber - 1)].onRelease();
    this.playlist.songs["link" + (trackNumber - 1)].gotoAndPlay(2);
} // End of the function
var repeatCurrentTrack = false;
var baseIY = informer.ttxt._x;
var f = null;
var aaa;
var D;
var file_description = [];
var CURSOUND = {};
var nextSong;
var playAtStart = false;
var LOAD = !playAtStart;
var openPlayList = true;
!playAtStart ? (play_pause.gotoAndStop(2)) : (play_pause.gotoAndStop(1));
MovieClip.prototype.init = function (Text)
{
    this.txtc.txt.text = Text;
    this.onRollOver = function ()
    {
        this.gotoAndPlay(2);
    };
    this.onRollOut = function ()
    {
        this.gotoAndPlay(8);
    };
};
list.onRelease = function ()
{
    if (openPlayList)
    {
        for (i in playlist.songs)
        {
            playlist.songs[i]._visible = true;
        } // end of for...in
        _global.PrevSong001._alpha = 60;
        playlist.roll(playlist.topY, 20);
        openPlayList = false;
    }
    else
    {
        playlist.roll(playlist.baseY, 25);
        openPlayList = true;
    } // end else if
};
play_pause.onPress = function ()
{
    timeline.loader.clicker.enabled = true;
    if (playAtStart)
    {
        this.gotoAndStop(2);
        textSetter("Track paused", "0x777777");
        informer.ttxt._x = baseIY;
        Mposition = musicObj.position;
        musicObj.stop();
        playAtStart = false;
    }
    else
    {
        this.gotoAndStop(1);
        textSetter(CURSOUND.Description, "0x777777");
        this._parent.LOAD ? (loadSound(this._parent.CURSOUND.Url, true, this._parent.CURSOUND.Duration, this._parent.CURSOUND.ID)) : (musicObj.start(Mposition / 1000, 1));
        playAtStart = true;
        this._parent.LOAD = false;
    } // end else if
};
stop_.onRelease = function ()
{
    textSetter("Track Stopped", "0x777777");
    informer.ttxt._x = baseIY;
    delete timeline.onEnterFrame;
    informer.time.text = "00:00 / 00:00";
    playAtStart = false;
    play_pause.gotoAndStop(2);
    musicObj.start(0, 1);
    musicObj.stop();
    musicObj.loadSound(null);
    this._parent.LOAD = true;
    timeline.mask_loader.gotoAndStop(1);
    timeline.mask_position.gotoAndStop(1);
    timeline.loader.clicker.enabled = false;
};
next.onRelease = function ()
{
    this._parent.LOAD = false;
    if (this._parent.CURSOUND.ID > file_description.length - 2)
    {
        this._parent.CURSOUND.ID = 0;
        playlist.songs["link" + this._parent.CURSOUND.ID].onRelease();
    }
    else
    {
        ++this._parent.CURSOUND.ID;
        playlist.songs["link" + this._parent.CURSOUND.ID].onRelease();
    } // end else if
    playlist.songs["link" + this._parent.CURSOUND.ID].gotoAndStop(7);
    textSetter(CURSOUND.Description, "0x777777");
};
prev.onRelease = function ()
{
    this._parent.LOAD = false;
    if (this._parent.CURSOUND.ID < 1)
    {
        this._parent.CURSOUND.ID = file_description.length - 1;
        playlist.songs["link" + this._parent.CURSOUND.ID].onRelease();
    }
    else
    {
        --this._parent.CURSOUND.ID;
        playlist.songs["link" + this._parent.CURSOUND.ID].onRelease();
    } // end else if
    playlist.songs["link" + this._parent.CURSOUND.ID].gotoAndStop(7);
    textSetter(CURSOUND.Description, "0x777777");
};
repeat.onRelease = function ()
{
    repeatCurrentTrack = !repeatCurrentTrack;
    this._currentframe == 1 ? (this.gotoAndStop(2)) : (this.gotoAndStop(1));
};
var mouseListener = new Object();
mouseListener.onMouseDown = function ()
{
    if (!playlist.hitTest(_root._xmouse, _root._ymouse, true))
    {
        if (!list.hitTest(_root._xmouse, _root._ymouse, true))
        {
            playlist.roll(playlist.baseY, 25);
            openPlayList = true;
        } // end if
    } // end if
};
Mouse.addListener(mouseListener);
loadSongsData();
gdzie odpowiednio next, prev, stop itp odpowiadaja przyciskom nawigacyjnym,
a "play_pause" to nazwa instancji dla przycisku startujacego i pauzujacego.


pozdrawiam
Ostatnio zmieniony wt kwie 08, 2008 6:14 pm przez tweakman, łącznie zmieniany 1 raz.
Marek_bf
Administrator
Posty: 4419
Rejestracja: czw lut 24, 2005 2:14 am
Kontakt:

Re: [AS 2] Mp3 player - autoplay

Post autor: Marek_bf »

Popraw temat
tweakman
Posty: 12
Rejestracja: ndz lut 25, 2007 2:40 pm

Re: [AS 2] Mp3 player - autoplay

Post autor: tweakman »

ktokolwiek pomoze?
ODPOWIEDZ