Link to home
Start Free TrialLog in
Avatar of wheelsfalloffbandwagons
wheelsfalloffbandwagons

asked on

Getting an FLV to loop twice in Actionscript 2

Hi all, I'm trying to get a video to loop only twice in an AS2 Flash banner. The sound also has to play only the first time the video plays, not the second time. Any ideas?

Here's my current code (I have var plays = 0; in the main timeline):
 
on(complete){
	if(plays > 1){
		this.stop();
	} else {
		plays++;
		this.autoRewind = true;     
	this.play();
	this.volume = 0;
	}
}

Open in new window


Many thanks in advance :]
ASKER CERTIFIED SOLUTION
Avatar of conagraman
conagraman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
conagraman suggested a form of what I'd do. For filesize and load reasons, I'd use the same FLV so it doesn't need to load 2 flv's (one with sound, one without) To achieve your sound issue on the 2nd loop, you could then use this line of code on your main timeline to stop all sounds on the 2nd clip:

stopAllSounds();

Open in new window

you also could just have the one movie clip and use a hidden textbox on your stage to hold your variable. once the mc has played once change the variable to 2. at the beginning check what number is in that hidden text box if it’s a 1 play the sound if the number is a 2 then use the stopAllSounds(); or volume = 0.  using hidden textboxes is a good way to hold a "global variable" i do this all the time.
have you embedded your flv into the timeline or are you using the flv component?
Avatar of wheelsfalloffbandwagons
wheelsfalloffbandwagons

ASKER

Thank you all very much for the replies. I could do it the way conagraman mentioned, one with a volume of 100 and the other with a volume of 0; but I was hoping that there would be a more elegant code solution. blue-genie, I am using the component as opposed to NS. Anyone have a more elegant code solution? Jen0910, the this.volume = 0; works just fine; sorry forgot to mention that the issue is with the looping rather than the sound. Thanks again :]
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Brill, many thanks :]
here's my suggestion whether it's more elegant or not I don't know but with all due respect,  I don't agree with the suggestions posted here.
You're using a component that has many built in features you can access - so make use of it.


have an instance of the flvplayback on the stage.
give it an instance name (in this case flvComp);
use the following code

please shout if you want explaining.
import mx.video.*;
var playCount:Number= 0; \\keep track how many times played
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void
{
playCount++;
flvComp.play();
flvComp.volume = 0;
} else {
trace("stop playing");
}
flvComp.addEventListener("complete", listenerObject);
flvComp.contentPath ="file.flv"; //path to your flv

Open in new window

ooooooooooh that's more like it! Knew there must have been a solution like that to it. Am I able to award any more points? :\ Many thanks, blue-genie; you're normally the one to help me out! Worked like a charm.
ooops, forgot to mention that this was the code I ended-up using. You forgot the IF statement.
import mx.video.*;
var playCount:Number= 0; 
var listenerObject:Object = new Object();
listenerObject.complete = function(eventObject:Object):Void
{
	if(playCount <> 1){
	playCount++;
	flvComp.play();
	flvComp.volume = 0;
} else {
	flvComp.stop();
}
}
flvComp.addEventListener("complete", listenerObject);
flvComp.contentPath ="video.flv";

Open in new window


Thanks again, hope this helps someone :]
argh sorry was typing the code out from my laptop onto my desktop - but my if statement was if playCount < 2 - but either works
:-)
For AS2 solution, maybe the following will work:

on(complete){
      if(_root.plays > 1){
            this.stop();
      } else {
            _root.plays++;
            this.autoRewind = true;    
      this.play();
      this.volume = 0;
      }
}

Otherwise, it will say plays NAN since the video action is not on the mainline.