Solved

Can I limit a flash .swf object to replay three times without having .fla file

Posted on 2011-02-10
2
538 Views
Last Modified: 2012-05-11
Is there a way to limit a flash .swf object to only repeating three times.

I do not have access to the .fla file, so I can't do this from within the code.

0
Comment
Question by:birwin
2 Comments
 
LVL 3

Expert Comment

by:dtocci
ID: 34866381
Using the flash embed parameters you can only tell it whether to loop indefinitely or not. There's no direct way to specify the number of times without the .fla file. If you know how long the swf takes to play once, I suppose you could remove the embedded object with javascript after that amount of time multiplied by three, but that's not a very elegant workaround.
http://kb2.adobe.com/cps/127/tn_12701.html
0
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 34867412
There's no elegant solution, but there is a solution...

You need to create a new Flash file that will act as the loader and "checker" for the loaded movie.

Add this code:
 
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;

var loader:Loader = new Loader();
var loopMax:int = 3;
var loopCount:int = 0;

startUp();

function startUp():void
{
	var urlRequest:URLRequest = new URLRequest("NeverStops.swf");
	loader.load(urlRequest);
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
}

function loadComplete(event:Event):void
{
	addChild(loader);
	loader.content.addEventListener(Event.ENTER_FRAME, checkFrame);
}

function checkFrame(event:Event):void
{
	var currObj:Object = event.currentTarget;
	if (currObj.currentFrame == currObj.totalFrames)
	{
		loopCount++;
		if (loopCount == loopMax)
		{
			currObj.gotoAndStop(currObj.totalFrames);
		}
	}
}

Open in new window


Change "NeverStops.swf" to whatever the file you have is named. Also, this works for ActionScript 3.0. If the file you're loading is AS2 it won't work, and you'll need the "AS2" version, if so just let me know and I'll post it over here.

Attached are the fla and the swfs.

Good luck,
-V
NeverStops.swf
FrameChecker.swf
FrameChecker.fla
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This video teaches users how to migrate an existing Wordpress website to a new domain.
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

919 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

22 Experts available now in Live!

Get 1:1 Help Now