Advertisement

10.07.2008 at 07:45AM PDT, ID: 23793903 | Points: 500
[x]
Attachment Details

Preloading multiple swfs in as3 breaks scripts in library clips

Asked by ardivus in ActionScript

Tags: ,

I am building a swf player that loads 4-6 swf files.
I would like to preload the subsequent swfs while previously loaded files are playing.

When I compile the player, any swfs that are playing while another is loading loses the actions in library clips in the swf.

For example, say there are a couple of simple swf files, "Movie1" and "Movie2".  Both have several movieclips in them and each movieclip has a stop action so it doesn't loop.
A third movie "Player" loads "Movie1", and starts playing it once the Event.INIT event is dispatched.
Once the Event.COMPLETE event is dispatched, "Player" begins loading "Movie2".
"Movie1" is still playing while "Movie2" loads.
As Movie1 plays, the library clips ignore the stop frame.

If I wait until Movie1 finishes playing, then load Movie2, I do not have the problem (but then the user has to wait for it to load)

When creating an example to post, I found that I only have the problem when I run the player locally -- both from flash player and from Firefox (and it does not matter if the movies are local or hosted on an external server, I always have the problem)

BUT, if I put the player on an external server, I do not have the problem!

I am worried that I am just lucky that it works from a server for me and that someone else will have the problem so, my question is:
Why would I have this problem locally but not from a server?
Am I just lucky that it is working for me from the server?

I tried to make a fairly simple example to post.  I know it is sloppy, but hopefully it will show you whatever I'm doing wrong.
I just put the following code on the first (and only) frame.  There is nothing else in the player.
When I run the code locally, the balls do not stop bouncing in the first clip, but they stop in the second clip.

I am using a Mac, and this is written in AS3Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
var loader1:Loader = new Loader();
var loader2:Loader = new Loader();
 
var sURL1:String = "http://www.lmnopo.com/temp/testswf3.swf";
var sURL2:String = "http://www.lmnopo.com/temp/testswf4.swf";
 
loader1.contentLoaderInfo.addEventListener(Event.INIT,loadInit1);
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete1);
loader1.load(new URLRequest(sURL1));
 
function loadInit1(e:Event):void{
	trace("initiated 1");
	var tempClip1:MovieClip = MovieClip(loader1.content);
	tempClip1.addEventListener(Event.ENTER_FRAME,enterFrame);
	addChild(tempClip1);
}
 
function loadInit2(e:Event):void{
	trace("initiated 2");
	var tempClip2:MovieClip = MovieClip(loader2.content);
	addChild(tempClip2);
	tempClip2.gotoAndStop(1);
	tempClip2.visible = false;
}
 
function loadComplete1(e:Event):void{
	trace("load 1 complete");
	loader2.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete2);
	loader2.contentLoaderInfo.addEventListener(Event.INIT,loadInit2);
	loader2.load(new URLRequest(sURL2));
}
 
function loadComplete2(e:Event):void{
	trace("load 2 complete");
}
 
function enterFrame(e:Event):void{
	if(e.target.currentFrame >= e.target.totalFrames){
		var tempClip2:MovieClip = MovieClip(loader2.content);
		tempClip2.visible = true;
		e.target.visible = false;
		tempClip2.addEventListener(Event.ENTER_FRAME,enterFrame2);
		tempClip2.play();
		e.target.gotoAndStop(1);
	}
}
 
function enterFrame2(e:Event):void{
	if(e.target.currentFrame >= e.target.totalFrames){
		var tempClip1:MovieClip = MovieClip(loader1.content);
		tempClip1.visible = true;
		e.target.visible = false;
		tempClip1.addEventListener(Event.ENTER_FRAME,enterFrame);
		tempClip1.play();
		e.target.gotoAndStop(1);
	}
}
[+][-]10.15.2008 at 05:41AM PDT, ID: 22720239

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 10:26AM PDT, ID: 22723481

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 12:06PM PDT, ID: 22724495

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 01:01PM PDT, ID: 22725169

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628