Member Avatar for Member #339485

Hello
I have purchase a template and need some help with changing the music in the template. I have never seen this type of action script before so I am not sure how the music is loading. I am used to seeing it in the time line and library which it is not.
I don't see a icon for the music in the libary. I only see a movie clip called player and a movie clip called sound componet that both have some action script ing that reads the following:

var numtrack = 1;
var maxTracks = 3;
var my_sound:Sound = new Sound();

var _this:MovieClip = this;

var txt:TextField = this.txt;
txt.autoSize = true;

//
my_sound.onLoad = function(success:Boolean) {
    if (success) {
        _this.txt.text = "";

        my_sound.start();
        _this.txt._x = 0;
        clearInterval(_this.interval);
    }
};

my_sound.loadSound("music/track1.mp3", false);

function loader(sound:Sound) {
    if (sound.getBytesLoaded() != undefined && sound.getBytesTotal() != undefined){
        var gbl:Number = sound.getBytesLoaded();
        var gbt:Number = sound.getBytesTotal();
    } else {
        var gbl:Number = 0;
        var gbt:Number = 100;
    }
    _this.txt.text = "track "+numtrack+" "+"loading "+Math.round(gbl/gbt*100)+"%";
    //_this.txt._x = -15 - _this.txt._width;
   
    if (gbl >= gbt){
        _this.txt.text = "";
    }
}

my_sound.onSoundComplete = function() {
    numtrack++;
    if (numtrack == 4) {
    numtrack = 1;
    }
    my_sound.loadSound("music/track"+numtrack+".mp3", false); var interval:Number = setInterval(_this, "loader", 1, my_sound); } // var interval:Number = setInterval(_this, "loader", 1, my_sound); // player controls btnNext.onRelease = function() {
    numtrack++;
    if (numtrack == maxTracks+1) {
        numtrack = 1;
    }
    my_sound.loadSound("music/track"+numtrack+".mp3", false);
    _this.interval = setInterval(_this, "loader", 1, my_sound); };

btnPrev.onRelease = function() {
    numtrack--;
    if (numtrack == 0) {
        numtrack = 3;
    }
    my_sound.loadSound("music/track"+numtrack+".mp3", false);
    _this.interval = setInterval(_this, "loader", 1, my_sound); };

btnStop.onRelease = function() {
    my_sound.start();
    my_sound.stop();
};

btnPlay.onRelease = function() {
    my_sound.stop();
    my_sound.start();
};

THIS WAS ALSO SOME ADDED SCRIPT IN A MOVIE CLIP CALL SOUND- COMPONET

var s_volume = 40;
var widthVolumeLine = s._width;
s._width = s_volume*widthVolumeLine/100; var mySound = new Sound(); var maxvolume = 100; var minvolume = 0; var soundFlag = false; controlSound.onEnterFrame = function() {
    mySound.setVolume(s_volume);
    if (soundFlag == true) {
        s._width = _xmouse;
        if (s._width>69) {
            s._width = 69;
        }
        // end if             
        if (s._width<0 || _xmouse<0) {
            s._width = 0;
        }
        // end if             
        s_volume = s._width*1.520000;
    }
};
var mouseListenerVolume:Object = new Object(); mouseListenerVolume.onMouseDown = function() {
    if (controlSound.hitTest(_root._xmouse, _root._ymouse)) {
        soundFlag = true;
    }
};
mouseListenerVolume.onMouseUp = function() {
    soundFlag = false;
};
Mouse.addListener(mouseListenerVolume);

Hopefully this is something simple. I just want to change the song and I am not sure what is happening here.
Please help anyone.
I am new at this which I sure you can tell.
Thanks
Mary

Dani AI

Generated

A quick, practical summary tied to the replies: the template plays MP3s that are loaded at runtime rather than embedded in the Library, so swapping music is done by replacing the external files or by changing the file paths the player loads. already pointed out where to look; the important follow‑ups are how to make the player use just one song and how to make the volume control actually affect that playback.

To keep a single song: open the player clip’s Actions panel and find the sound‑completion logic (the callback that runs when a track finishes). Remove or simplify the part that advances to the next file — either stop advancing at all, or have it reload the same file if a continuous loop is wanted. Alternatively, set the player’s track count to one so the loop code never advances. Save a backup of the FLA before editing.

Volume control gotcha: the template’s volume UI appears to create a separate Sound instance from the one doing the playback. If the slider changes do not affect the music, have the slider call the same Sound instance that loaded the MP3 (for example by storing the player’s Sound object on _root or otherwise exposing it so the control can call its setVolume method). That keeps playback and volume control in sync.

Troubleshooting and references: test locally with the external music folder present (missing files will simply not play), and use Flash’s trace/debug output if available. For exact Sound methods and behaviour in ActionScript 2.0, consult Adobe’s class reference for the Sound object: .

Recommended Answers

All 6 Replies

my_sound.loadSound("music/track1.mp3", false); This tells me that the music is being downloaded and is not actually in the flash movie or library. Look in the folder that you downloaded. It should contain a subfolder named music. Inside (I think) will contain mp3's named track1.mp3,track2.mp3, & track3.mp3.

my_sound.onSoundComplete = function() {
numtrack++;
if (numtrack == 4) {
numtrack = 1;
}

This is incrementing the track number by one at the end of the song and resetting the song number after track3.mp3. To change the songs, take the mp3's that you want in the player and name them track1.mp3, track2.mp3...and replace the current songs in the music folder.

This is all just a guess but hopefully it will help get you going in the right direction.

commented: Good code example +8
Member Avatar for Member #339485

Thanks this helped what if I want to just have one song. What do I need tho change

my_sound.onSoundComplete = function() {
numtrack++;
if (numtrack == 2) {
numtrack = 1;
}
Member Avatar for Member #339485

Thanks for the help
Appreciate it very much

No problem, please dont forget to mark the post as solved.

Member Avatar for Member #339485

How do I marked it solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.