0
votes

I have an AS3 function that loads and audio file and then plays it. I have the pre-loader for the first audio file working - now I need to run the pre-load function before the 2nd audio file starts.

myMusic.addEventListener(ProgressEvent.PROGRESS, onLoadProgress2, false,0, true);
    myMusic.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
myMusic.load(soundFile, myContext); //This code works

Here is the play code:

//This code doesn't work

function receiveText1(value:String):void {

        channel.stop();
        channel2.stop();
        songPosition = 0;
        soundFile2 = new URLRequest(jsVariableValue1);
        myMusic2= new Sound();  //Intstantation
        myMusic2.load(soundFile2, myContext);
            //need to run preloader here
        soundFile2exist = null;
        }

Here is my event listener and preloader:

myMusic2.addEventListener(ProgressEvent.PROGRESS, onLoadProgress, false,0, true);
    myMusic2.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);

function onLoadProgress(evt:ProgressEvent):void {
    progBar.alpha = .70;
    prcLoaded.alpha = .70;
    var pcent:Number=evt.bytesLoaded/evt.bytesTotal*100;
    prcLoaded.text =int(pcent)+"%";
    progBar.width =  90 * (evt.bytesLoaded / evt.bytesTotal);
}

I thought I could call

onLoadProgress(evt:ProgressEvent);

from within the function, but I'm getting an error

1084: Syntax error: expecting rightparen before colon.
2
Is that a compile error or a runtime error?Jacob Eggers
you cannot call a function declaring the types of an argument. Think about creating a shared funtion by your listener function and another place on your code.papachan
So is it possible to call that same function? Or should I be putting my event listeners within the recieveText1 function?user547794
It seems to me that putting the event listener outside the function should listen for myMusic2.load to begin loading. Once this happens, it should run the onLoadProgress function. What am I missing?user547794
@ Jacob this is a compile erroruser547794

2 Answers

0
votes

I added the event listeners inside the function and all is right now.

0
votes

why you want to call manually the "onLoadProgress" ?
It should be executed automatically (if your file is not cached, and you are adding the listener correctly
I see your addEventListener in your question, but you are not showing where/when you are adding this listener.

Anyway, if you want to execute your onLoadProgress you should do something like this:

var bytesLoaded:uint = 50;
var bytesTotal:uint = 100;
var evt:ProgressEvent = new ProgressEvent( ProgressEvent.PROGRESS, false, false, bytesLoaded, bytesTotal);
onLoadProgress(evt);   

You must note that you need to create a "fake" Progress event, and assign fakes bytesLoaded and bytesTotal values.
And even knowing that the onLoadProgress will be executed just once.
And I'm sure that is not what you want.

Please explain better what are you trying to do.