Solved

Preloading multiple swfs in as3 breaks scripts in library clips

Posted on 2008-10-07
5
908 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flash media server 1 326
anti-download video publishing site? 6 610
Action Script commands 5 234
how can i learn adobe flex step by step 4 94
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now