Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting an FLV to loop twice in Actionscript 2

Posted on 2011-09-28
12
Medium Priority
?
1,095 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 1000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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
 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

772 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