Solved

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

Posted on 2011-02-10
2
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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)
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

751 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