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

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 :]
0
wheelsfalloffbandwagons
Asked:
wheelsfalloffbandwagons
  • 4
  • 3
  • 2
  • +2
2 Solutions
 
conagramanCommented:
well there are some obvious things you could do.
the first one would be to have two movie clips in different frames on your time line. one with sound one without sound. once the first mc is finished have it play the next frame which has the other movie clip.
0
 
Jen0910Commented:
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

0
 
conagramanCommented:
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.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
blue-genieCommented:
have you embedded your flv into the timeline or are you using the flv component?
0
 
wheelsfalloffbandwagonsAuthor Commented:
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 :]
0
 
Jen0910Commented:
conagraman's 2nd solution would be fine for a code-based option. When it plays the first time give it a 2, when it plays the second time give it a 3.Then simply add a check for a variable 3 on top of the 2 checks he suggests. That way If the hidden text box has that variable of 3, you can force it to stop.

variable return of 1 would be play
variable return of 2 would be play with stopAllSounds();
variable return of 3 would stop the movie, giving you only 2 loops.
0
 
wheelsfalloffbandwagonsAuthor Commented:
Brill, many thanks :]
0
 
blue-genieCommented:
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

0
 
wheelsfalloffbandwagonsAuthor Commented:
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.
0
 
wheelsfalloffbandwagonsAuthor Commented:
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 :]
0
 
blue-genieCommented:
argh sorry was typing the code out from my laptop onto my desktop - but my if statement was if playCount < 2 - but either works
:-)
0
 
tomteh1Commented:
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.
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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