Solved

Preloading multiple swfs in as3 breaks scripts in library clips

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

705 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

16 Experts available now in Live!

Get 1:1 Help Now