0

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));
}
JAL
  • 41,701
  • 23
  • 172
  • 300
Paul Fenn
  • 1
  • 1

2 Answers2

0

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

Timur Koshel
  • 179
  • 4
  • I checked google and the site link you posted above... a sound manager seems a little over board. These audio files would simply be a voice track that spoke the words on each page being loaded by the thumbnails. Do think this could be solved by using a loop and iterating through an XML doc? – Paul Fenn Nov 23 '15 at 22:56
  • yes, you can try use loop and iterate through XML or JSON doc – Timur Koshel Nov 24 '15 at 09:17
0

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();

}
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • Thank you, I will try your recommendations! What if everytime the thumbnail is clicked a different audio file is played. Could you tell me the easiest approach you would take? – Paul Fenn Nov 22 '15 at 23:39
  • I added the code you suggested but this fails to stop the music when moving to another clicked thumbnail. You will have to forgive my ignorance, I am still trying to learn AS. I think a loop and xml might be a cure for this but I am still not quite sure as to how to phrase the AS for this properly. I know it may be something like the xml being used for images but for sound... Any idea's? ;) – Paul Fenn Nov 25 '15 at 00:44
  • `...like the xml being used for images but for sound` Yes!! that's it exactly. You have `fullPath` as text string for image path now you could make a `songPath` and get that relevant entry from XML file. Then you can just have a line like `mySound.load( new URLRequest(songPath) );`. I'll look into the sound stop issue when I get a chance to run Flash soon-ish. – VC.One Nov 25 '15 at 01:37