Loop while sound position is less than sound duration

I understand loops, I understand if statements, I even understand position and duration.  What I don't get is how to put them all together to create a single frame loop based on the position of a sound object.

My syntax makes sense to me but does not work.  And thanks again in advance for looking.

So this is what I got so far




// sets variable for sound
var soundObj:Sound = new Sound(this);
// controls sound in movie
paraSoundStart = function (a) {
	paraSoundStop();
	soundObj.attachSound(a);
	soundObj.start();
};
//the loop
i = soundObj.position;
t = soundObj.duration;
while (i<t) {
	if (i<t) {
		//stay on current frame
	} else {
		//advance to next frame
	}
}

Open in new window

frankybonesAsked:
Who is Participating?
 
Aneesh ChopraCommented:
While loop runs all at once with in the framecode,
you need an event which can check after a timeInterval so that each code frame can get executed.

I updated your code and used "onEnterFrame" event,
Below is working code, just change "sound instance linkage ID"
stop();
// sets variable for sound
var soundObj:Sound = new Sound(this);
// controls sound in movie
paraSoundStart = function (a) {
	paraSoundStop();
	soundObj.attachSound(a);
	soundObj.start();
};
 
paraSoundStart("sound1");
//the loop
 
this.onEnterFrame = function(){
	var i = soundObj.position;
	var t = soundObj.duration;
	trace("i:"+i+" & t: "+t );
	if (i<t) {
		//stay on current frame
	} else {
		// stop onEnterFrame loop
		delete this.onEnterFrame;
		//advance to next frame
		gotoAndStop(this._currentframe+1);
	}
}

Open in new window

0
 
frankybonesAuthor Commented:
wow...have i been black listed?
0
 
frankybonesAuthor Commented:
Thank you very much for your help.  It is greatly appreciated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.