Paul Fenn
Paul Fenn

Reputation: 1

I am looking for a simple solution to loading a new/different mp3 sound file upon clicking a thumbnail using my existing code below

This seems simple enough, I just can't crack it though.

currently, in the below code. its a UILoader with a series of thumbnail mc's horizontally across the bottom of the FLA. when the thumbs are clicked and new SWF loads in the UI.

I am simply looking for the error of my ways, hopefully by simply added to this code and a possible explanation. I need to figure out how to play/stop on exit and new mp3 sound file.

UILoader With movieClips used for thumbnail loads

var imagesXML:XML;
var xmlLoader: URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("lessons/images/Images5.xml"));

/////////////////////////////////////////////////////////////
////////////    thumbnail loader    /////////////////////////

function xmlLoaded(evt:Event):void
{
    imagesXML = new XML(xmlloader.data);
    var thumbLoader:UILoader;
    for(var i:uint = 0; i < imagesXML.image.length(); i++)
        {
            thumbLoader UILoader(getChildByName("thumb" + 1));
            thumbLoader.load(new URLRequest("lessons/images/thumbs/" + imagesXML.image[i].@file));
            thumbLoader.buttonmode = true;
            thumbLoader.addEventListener(MouseEvent.CLICK, thumbClicked);
            var fullPath:String = "lessons/images/file-1.swf";
            mainLoader.load(new URLRequest(fullpath));
        }
}



/////////////////////////////////////////////////////////////
////////////////   load Images  /////////////////////////////

function thumbClicked(evt:MouseEvent):void
{
        var thumbName:String = evt.currentTarget.name;
        var thumbIndex:uint = uint(thumbName.substr(5));
        var fullPath:String = "lessons/images/" + imagesXML. image[thumbIndex].@file;
        mainLoader.load(new URLRequest(fullPath));
}

Upvotes: 0

Views: 43

Answers (2)

VC.One
VC.One

Reputation: 15881

Declare sound object outside of functions so it is available to all functions

var mySound:Sound;
var myChannel:SoundChannel; 

function thumbClicked(evt:MouseEvent):void
{
        var thumbName:String = evt.currentTarget.name;
        var thumbIndex:uint = uint(thumbName.substr(5));
        var fullPath:String = "lessons/images/" + imagesXML. image[thumbIndex].@file;
        mainLoader.load(new URLRequest(fullPath));

        //stop any already playing sound
        if ( myChannel != null) { myChannel.stop(); } 

        //load an MP3 file
        mySound = new Sound();  mychannel = new SoundChannel();
        mySound.load(new URLRequest("myAudio.mp3"));
        mySound.play();

}

Upvotes: 0

Timur Koshel
Timur Koshel

Reputation: 179

you can try to use this library https://github.com/treefortress/SoundAS or try to google "Sound manager for as3" and I sure you will find library you like

Upvotes: 0

Related Questions