Solved

Getting an FLV to loop twice in Actionscript 2

Posted on 2011-09-28
12
1,026 Views
Last Modified: 2012-05-12
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
Comment
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 10

Accepted Solution

by:
conagraman earned 250 total points
ID: 36718312
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
 
LVL 8

Expert Comment

by:Jen0910
ID: 36718436
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
 
LVL 10

Expert Comment

by:conagraman
ID: 36718931
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 36719870
have you embedded your flv into the timeline or are you using the flv component?
0
 

Author Comment

by:wheelsfalloffbandwagons
ID: 36720356
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
 
LVL 8

Assisted Solution

by:Jen0910
Jen0910 earned 250 total points
ID: 36720393
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Closing Comment

by:wheelsfalloffbandwagons
ID: 36720464
Brill, many thanks :]
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 36813210
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
 

Author Comment

by:wheelsfalloffbandwagons
ID: 36813544
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
 

Author Comment

by:wheelsfalloffbandwagons
ID: 36813650
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 36813787
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
 

Expert Comment

by:tomteh1
ID: 37546547
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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now