• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

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

0
frankybones
Asked:
frankybones
  • 2
1 Solution
 
frankybonesAuthor Commented:
wow...have i been black listed?
0
 
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:
Thank you very much for your help.  It is greatly appreciated.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now