Skip to main content
Participating Frequently
November 30, 2019
Question

Play different SWF one after another

  • November 30, 2019
  • 1 reply
  • 579 views

Hello

 

I'm looking for a way to play different Animations (SWF) after each other with the following sequence made in Animate/Flash:

 

1. Load SWF 1 + 2 + 3...

2. When all are loeaded, wait. Do not start!

3. After klick "Play" the first SWF starts

4. At the end of SWF 1 the SWF 2 automatically starts

5. go ahead with SWF 3 + 4 .....

 

And it is important, that the crossing from 1 to 2 is exactly in time. So Frame by Frame. A solution with a time counter will not work due to synchronisation.

And it has to work on a local computer. Not online.

 

Thanks very much for your input!

 

Greez

Yuna

This topic has been closed for replies.

1 reply

JoãoCésar17023019
Community Expert
Community Expert
December 1, 2019

Hi.

 

Here is an example of how you could do this.

 

Main FLA/SWF AS3 code for the 1st frame:

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;

var swfs:Vector.<String> = new <String>["test0.swf", "test1.swf", "test2.swf", "test3.swf"];
var swfContainers:Vector.<MovieClip> = new <MovieClip>[swf0, swf1, swf2, swf3];
var loaders:Vector.<Loader> = new Vector.<Loader>(swfs.length, true);
var swfCount:uint = 0;
var queueCount:uint = 0;

function start():void
{
	disablePlayButton();
	loadQueue();
	playButton.addEventListener(MouseEvent.CLICK, playNext);
}

function loadQueue():void
{
	for (var i:int = 0, total:int = swfs.length; i < total; i++)
	{
		loaders[i] = loadSWF(swfs[i]);
		loaders[i].contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
	}
}

function loadSWF(url:String):Loader
{
	var loader:Loader = new Loader();
	var urlRequest:URLRequest = new URLRequest(url);
	loader.load(urlRequest);
	return loader;
}

function swfLoaded(e:Event):void
{
	swfCount++;
	
	if (swfCount == swfs.length - 1)
		enablePlayButton();
}

function playNext(e:MouseEvent):void
{	
	var timeline:MovieClip;
	
	swfContainers[queueCount].addChild(loaders[queueCount]);
	timeline = MovieClip(loaders[queueCount].content);
	timeline.gotoAndPlay(1);
	
	if (queueCount === 0)
		disablePlayButton();
	
	queueCount++;
}

function enablePlayButton():void
{
	playButton.mouseEnabled = true;
	playButton.alpha = 1;
}

function disablePlayButton():void
{
	playButton.mouseEnabled = false;
	playButton.alpha = 0.5;
}

start();

 

Child FLA/SWF AS3 code for the last frame (except for the last FLA/SWF):

stop();

if (parent.parent)
{
    MovieClip(parent.parent.parent).playNext(null);
}

 

Source / FLA / files:

https://github.com/joao-cesar/adobe/tree/master/animate%20cc/as3/load_swfs_and_play_in_sequence

 

 

I hope this helps.

 

 

Regards,

JC

Yuna-LiAuthor
Participating Frequently
December 1, 2019

Dear JoãoCésar


First, thank you very very much for your detailed anser! I really appreciate that!


Since I'm a newbie in Actionscript I try just to copy your code in a new project. Created 4 animations and put the name in your array in line 8.


Just without doing something else, I excecute the code. And first i receive the error for not defined variable. So I disabled "Strict Mode". If I publish now, it creates no errors. But also nothing happens.

If I do not publish but say preview (CTRL+Enter) I get an reference error #1065: Variable swf0 is not defined.

Since I have no idea for what you are using this row, I don't know how to fix it.

Further you create a Play Button right? Do I have to define a Button at the stage for this function?


Thanks for helping a stupid newbie run its simple code...

Greetings Yuna

JoãoCésar17023019
Community Expert
Community Expert
December 1, 2019

You're welcome!

 

And have you tried downloading the files here:

https://github.com/joao-cesar/adobe/tree/master/animate%20cc/as3/load_swfs_and_play_in_sequence

?

 

If you have, even starting from the files provided are you encountering the issues mentioned?