Solved

Getting an FLV to loop twice in Actionscript 2

Posted on 2011-09-28
12
1,020 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

758 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

20 Experts available now in Live!

Get 1:1 Help Now