Solved

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

Posted on 2011-02-10
2
536 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

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

19 Experts available now in Live!

Get 1:1 Help Now