Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-10
2
Medium Priority
?
549 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 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

670 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