Solved

Preloading multiple swfs in as3 breaks scripts in library clips

Posted on 2008-10-07
5
923 Views
Last Modified: 2013-11-11
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 AS3
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);
	}
}

Open in new window

0
Comment
Question by:ardivus
[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
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 22720239
movie1 and movie2 share the same assets in the library?
0
 

Author Comment

by:ardivus
ID: 22723481
Nope, they are two completely unique, self-contained swfs loaded into player.  Each has its own assets.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 22724495
that's just wack. sorry i have nothing more profound,
nothing jumps out at me and screams i'm wrong, but i'm busy drinking a glass of wine.
question though. want are the onEnterFrames for.
also you've got listeners for complete events and init - which means the thing is loaded, so why the need to check currentframe vs totalframe?
can you zip up the lot and upload it? give it a another go that way..i just find it easier to debug seeing the error in action rather than sifting through code in my head.
oh and another thing make sure you remove your listeners, once its loaded and available you don't care anymore yeah, so kill them.
oh and those library clips that arent' stopping, they're on the stage already? or you doing addChild later on?
0
 

Author Comment

by:ardivus
ID: 22725169
The complete and init listeners are to handle the loading of the clips.

The enterframe listener and the currentframe vs totalframe are to control playback.  They watch for the last frame of the currently playing clip, then start playing the other one.  I guess I should probably have left that out of this quick example for clarity's sake.

For some reason I can't add the zip file created by my mac, the Experts-Exchange attach file uploader keeps rejecting it.  However, you can download it from here:  http://www.lmnopo.com/temp/PreloadSwfs.zip

When using it, please remember that the two loaded swfs come in too quickly and don't manifest the problem if you load them locally, so I am loading them from a web server.

Thanks for the tip on the removeeventlistener.  I know this is a sloppy example, and I am cleaning stuff up right in the real app.

As for the library clips.  They are clips from each of the loaded movie's libraries.  They do not exist on the stage of those movies until they are needed.  (in my real application it is not possible to have the clips load into the first frame of the loaded movies).

I'm afraid that my explanations make it more confusing, but hopefully it will make more sense when you grab the files and try it out on your own.

Thanks for your help!
0
 

Accepted Solution

by:
ardivus earned 0 total points
ID: 23724924
Well... I never found a solution to the problem, but I need the points for another question.  Thanks blue-genie for trying.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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 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.
Suggested Courses

636 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