lundi 30 novembre 2015

Have any idea's of getting a new audio file to play with every click of this lesson?

I am somewhat new to AS but still trying to learn and accomplish what seems like tough stuff. I will prevail!

The code below shows my progress so far. I have a UI Loader that has a series of thumbnails. With each click of the thumbnail a new SWF file loads... well I'm trying to get an external series of mp3 files to do the same through an XML file. So far, I've managed to just get one audio file to play with every click AND it play over the existing file.

I simply want to get a new one to play with each thumbnail AND stop the previous audio file from playing if/when the user clicks a new thumbnail.

Please assist if me see the errors of my way. A little overwhelmed.

var imagesXML:XML;
var xmlLoader: URLLoader = new URLLoader();
xmlLoader.addEventlistener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(new URLRequest("lessons/images/Images5.xml"));
var thumbSounds:Dictionary = new Dictionary();

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

var mySound:Sound;
var myChannel:SoundChannel;

function xmlLoaded(evt:Event):void
imagesXML = new XML(;
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));
        thumbSounds[thumbLoader] = "lessons/audio/narration/ch1p" + thumbIndex + ".mp3";

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

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

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

// load mp3 file
//  mySound = new Sound(); myChannel = new SoundChannel();
//  mySound.load(new URLRequest ("lessons/audio/narration/ch1p3.mp3"));

Aucun commentaire:

Enregistrer un commentaire