Flash As help needed.

Mitch

New Member
Messages
908
Reaction score
0
Points
0
I have a flash mp3 player.
I start automatic.
I can't change that it not automatic plays my songs.

Mp3 player scrip:
mp3Player.as
Code:
// Setup sound object
var s:Sound = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);

// Array of songs
var sa:Array = new Array();

// Currently playing song
var cps:Number = -1;

// Position of music
var pos:Number;

// Load the songs XML
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
    var nodes:Array = this.firstChild.childNodes;
    for(var i=0;i<nodes.length;i++)
    {
        sa.push(new Song(nodes[i].attributes.url, nodes[i].attributes.artist, nodes[i].attributes.track));
    }
    playSong();
}

xml.load("songs.xml");

// Play the MP3 File
function playSong():Void
{
    s = new Sound();
    s.onSoundComplete = playSong;
    s.setVolume(75);
    mute.gotoAndStop("on");
    if(cps == sa.length - 1)
    {
        cps = 0;
        s.loadSound(sa[cps].earl, true);
    }
    else
    {
        s.loadSound(sa[++cps].earl, true);
    }
    trackInfo.text = sa[cps].artist + " - " + sa[cps].track;
    playPause.gotoAndStop("pause");
    textPos = 0;
}

// Pauses the music
function pauseIt():Void
{
    pos = s.position;
    s.stop();
}

// Pauses the music
function unPauseIt():Void
{
    s.start(pos/1000);
}

// Music Controls

// Play/Pause Toggle
playPause.onRollOver = function()
{
    if(this._currentframe == 1) this.gotoAndStop("pauseOver");
    else this.gotoAndStop("playOver");
}

playPause.onRollOut = playPause.onReleaseOutside = function()
{
    if(this._currentframe == 10) this.gotoAndStop("pause");
    else this.gotoAndStop("play");
}

playPause.onRelease = function()
{
    if(this._currentframe == 10)
    {
        this.gotoAndStop("playOver");
        this._parent.pauseIt();
    }
    else
    {
        this.gotoAndStop("pauseOver");
        this._parent.unPauseIt();
    }
}

// Next Button
next.onRollOver = function()
{
    this.gotoAndStop("nextOver");
}

next.onRollOut = next.onReleaseOutside = function()
{
    this.gotoAndStop("next");
}

next.onRelease = function()
{
    this._parent.playSong();
}

// Mute Button
mute.onRollOver = function()
{
    if(this._currentframe == 1) this.gotoAndStop("onOver");
    else this.gotoAndStop("offOver");
}

mute.onRollOut = mute.onReleaseOutside = function()
{
    if(this._currentframe == 10) this.gotoAndStop("on");
    else this.gotoAndStop("off");
}

mute.onRelease = function()
{
    if(this._currentframe == 10)
    {
        this.gotoAndStop("offOver");
        s.setVolume(0);
    }
    else
    {
        this.gotoAndStop("onOver");
        s.setVolume(75);
    }
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Text scroller bonus code

var size:Number = 21;
var textPos:Number = 0;
var intervalID:Number = setInterval(scroller, 1000);

function scroller():Void
{
    var t:String = (sa[cps].artist + " - " + sa[cps].track);
    if(textPos+size < t.length)
    {
        textPos++;
        trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, textPos+size);
    }
    else 
    {
        clearInterval(intervalID);
        intervalID = setInterval(scroller2, 1000);
    }
}

function scroller2():Void
{
    var t:String = (sa[cps].artist + " - " + sa[cps].track);
    if(textPos > 0)
    {
        textPos--;
        trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, size);
    }
    else 
    {
        clearInterval(intervalID);
        intervalID = setInterval(scroller, 1000);
    }
}

There are more files, but you only need this file to change it.
 

Sohail

Active Member
Messages
3,055
Reaction score
0
Points
36
Maybe you should use a button to start the music..?
 

Mitch

New Member
Messages
908
Reaction score
0
Points
0
I am not that good in this.

Could someone change it to that you need to start the music with button, but no autoplay!
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
Code:
// Setup sound object
var s:Sound = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);

// Array of songs
var sa:Array = new Array();

// Currently playing song
var cps:Number = -1;

// Position of music
var pos:Number;

// Load the songs XML
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
    var nodes:Array = this.firstChild.childNodes;
    for(var i=0;i<nodes.length;i++)
    {
        sa.push(new Song(nodes[i].attributes.url, nodes[i].attributes.artist, nodes[i].attributes.track));
    }
}

xml.load("songs.xml");

// Play the MP3 File
function playSong():Void
{
    s = new Sound();
    s.onSoundComplete = playSong;
    s.setVolume(75);
    mute.gotoAndStop("on");
    if(cps == sa.length - 1)
    {
        cps = 0;
        s.loadSound(sa[cps].earl, true);
    }
    else
    {
        s.loadSound(sa[++cps].earl, true);
    }
    trackInfo.text = sa[cps].artist + " - " + sa[cps].track;
    playPause.gotoAndStop("pause");
    textPos = 0;
}

// Pauses the music
function pauseIt():Void
{
    pos = s.position;
    s.stop();
}

// Pauses the music
function unPauseIt():Void
{
    s.start(pos/1000);
}

// Music Controls

// Play/Pause Toggle
playPause.onRollOver = function()
{
    if(this._currentframe == 1) this.gotoAndStop("pauseOver");
    else this.gotoAndStop("playOver");
}

playPause.onRollOut = playPause.onReleaseOutside = function()
{
    if(this._currentframe == 10) this.gotoAndStop("pause");
    else this.gotoAndStop("play");
}

playPause.onRelease = function()
{
    if(this._currentframe == 10)
    {
        this.gotoAndStop("playOver");
        this._parent.pauseIt();
    }
    else
    {
        this.gotoAndStop("pauseOver");
        this._parent.unPauseIt();
    }
}

// Next Button
next.onRollOver = function()
{
    this.gotoAndStop("nextOver");
}

next.onRollOut = next.onReleaseOutside = function()
{
    this.gotoAndStop("next");
}

next.onRelease = function()
{
    this._parent.playSong();
}

// Mute Button
mute.onRollOver = function()
{
    if(this._currentframe == 1) this.gotoAndStop("onOver");
    else this.gotoAndStop("offOver");
}

mute.onRollOut = mute.onReleaseOutside = function()
{
    if(this._currentframe == 10) this.gotoAndStop("on");
    else this.gotoAndStop("off");
}

mute.onRelease = function()
{
    if(this._currentframe == 10)
    {
        this.gotoAndStop("offOver");
        s.setVolume(0);
    }
    else
    {
        this.gotoAndStop("onOver");
        s.setVolume(75);
    }
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Text scroller bonus code

var size:Number = 21;
var textPos:Number = 0;
var intervalID:Number = setInterval(scroller, 1000);

function scroller():Void
{
    var t:String = (sa[cps].artist + " - " + sa[cps].track);
    if(textPos+size < t.length)
    {
        textPos++;
        trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, textPos+size);
    }
    else 
    {
        clearInterval(intervalID);
        intervalID = setInterval(scroller2, 1000);
    }
}

function scroller2():Void
{
    var t:String = (sa[cps].artist + " - " + sa[cps].track);
    if(textPos > 0)
    {
        textPos--;
        trackInfo.text = (sa[cps].artist + " - " + sa[cps].track).substring(textPos, size);
    }
    else 
    {
        clearInterval(intervalID);
        intervalID = setInterval(scroller, 1000);
    }
}

use this code, and
on the button add this:
Code:
    playSong();
 

snowdude

New Member
Messages
5
Reaction score
0
Points
0
further to diabolo's post:

you need to create a button by drawing a button (say, a box), then select it, and convert to a button (press F8, select button and hit ok).

then you need to enter the following code ON THE BUTTON itself, not on the main frame

Code:
on(release) {
_root.playSong();
}

then whenever anyone clicks the button, the song starts playing.

just clearing everything up :)

cheers
 

Mitch

New Member
Messages
908
Reaction score
0
Points
0
This music player works with Movie Clips.
I attach all the files of this music player.

The first one who has this fixed gets 30 credits. :biggrin: ;)
 

Attachments

  • mp3Player3.zip
    12.7 KB · Views: 2

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
hmmm this is a little tricky...
I have been able to make it play from a button..the only thing is that once you click on the button..it doesn't play..it goes to the next frame, but it doesn't start...you have to click on the 'next' button...I'll see what I can do..but right now I got a performance to go to

peace/.

update..ok I got it to play..now just the volume..I can't hear it..i kno its playing cuz of the scrolling text

done..I am so stupid...I could have just made a frame before it then redirect it to teh next frame..and let your script take over....using your flaw as a good thing.!
 

Attachments

  • mp3Player3.zip
    16.6 KB · Views: 5
Last edited:
Top