Solved

Need some help with a nice clean load script

Posted on 2003-11-25
9
270 Views
Last Modified: 2010-04-03
I'm afraid it's been a little while since I had to do any scripting in Flash and am looking for some advice/code for setting this up in the cleanest, most efficient way possible. Please excuse the overly detailed approach to this question.

preliminary
------------------------------------------->
Right now I have seperated my movie into 5 seperate files. The main movie really just contains a background and some text that stays consistent throughout. The other four movies are made up of one image each, and some accompaning text. I have gotten the largest of the 4 image files down to around 37k.

files:

welcome.swf ( this is the main movie with the background layer )

and the 4 image file movies:
welcomeComm.swf
welcomeData.swf
welcomeEvents.swf
welcomeOnline.swf

objective
------------------------------------------------->
I'd like to fade in welcomeComm.swf, display it for aprox. 5 seconds, fade it out and fade in welcomeData.swf and so on.

my initial approach
------------------------------------------------->

Not sure if this is the best way to do this, but I went the route of having four seperate named instances of an empty clips to load my swf into using loadMovie. ( I'm used to loading to levels instead of targets)

So frame 1 of my main movie just loads each swf into their respective clips and then sets each of their alphas to zero
Frame 2 has stop action on it and brings up the alpha on the first clip to 100 ( at this point I havent done any of the fade in/out stuff)
Frame 3 puts the alpha of the first clip back to zero and brings up the next and so on and so on. ( you get the picture - I hope)

To handle the five seconds thing, I just made a simple timer clip, aptly named 'timer' that would tell the root to go to the next frame when it got to 5.

the problem(s)
------------------------------------------------>
 - I'm still not totally convinced that what I've done so far is the most efficient approach.
 - I haven't figured out the best way to take care of the fade in/out this - whether I should do this by tweening in each individual swf, or if I could make another action clip that could change the alpha via actionscript. ( does one increase file size more than the other?)
- using my current method of basically a timed slide show :p when  I get to the end and want to start over, nothing is shown.

I'm going to put a bunch of points on this one as I'm looking for the cleanest, fastest loading, expandable ( if I want to add more image files) options.

Before anybody posts, my fla's can be downloaded here http://www.donorchoice.com/flash.zip

Thanx in advance, sorry for the ramble
Nick


0
Comment
Question by:nickleplated
  • 5
  • 4
9 Comments
 
LVL 1

Author Comment

by:nickleplated
ID: 9822064
Too much detail? Nobody wants to touch this one?

well I'm working on a fader clip anyway.

let me know if you have any ideas...

n
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9822148
I have deleted everything from your "welcome" fla, except the dotted line and the raster text.
Used only script ending with:

sample: http://www.negatyve.com/EE/externalSwfSlide/welcome.html
source: http://www.negatyve.com/EE/externalSwfSlide/externalSwfSlide.zip

>expandable ( if I want to add more image files) options.

external swf list come from an xml file, loaded at runtime. by this time it is:

=======================================
<?xml version="1.0" encoding="UTF-8"?>
<slides>
      <item src="welcomeEvents.swf"      />
      <item src="welcomeOnline.swf"      />
      <item src="welcomeData.swf"      />
      <item src="welcomeComm.swf"      />
</slides>
========================================

to expand it, you just need to add a new item this way (no fla editing involved):

=======================================
<?xml version="1.0" encoding="UTF-8"?>
<slides>
      <item src="welcomeEvents.swf"      />
      <item src="welcomeOnline.swf"      />
      <item src="welcomeData.swf"      />
      <item src="welcomeComm.swf"      />
      <item src="new_slide_file_name.swf"      />
</slides>
========================================

Everythin is managed by this code:

stop();
SWFSlider = {path:this};
SWFSlider.init = function()
{
      this.data_xml = new XML();
      this.data_xml.ignoreWhite = true;
      this.data_xml.path = this;
      this.data_xml.onLoad = function(success)
      {
            if(success){
                  this.path.initSlide();
            } else {
                  trace("XML FILE MISSING");
            }
      };
      this.data_xml.load("slides.xml");
};
SWFSlider.initSlide = function()
{
      var nodes = this.data_xml.firstChild.childNodes;
      this.slide_array = [];
      for(var i = 0; i < nodes.length; i++){
            this.slide_array.push(nodes[i].attributes["src"]);
      }
      this.curSlide = -1;
      this.maxSlide = this.slide_array.length;
      delete this.data_xml;
      this.nextSlide();
};
SWFSlider.nextSlide = function()
{
      if(this.curSlide < this.maxSlide - 1){
            this.curSlide++;
      } else {
            this.curSlide = 0;
      }
      this.loader.removeMovieClip();
      this.loader = this.path.createEmptyMovieClip("pic_loader", 15000);
      this.loader._alpha = 0;
      this.loader.loadMovie(this.slide_array[this.curSlide]);
      clearInterval(this.intervalID);
      this.intervalID = setInterval(this, "preloadSlide", 20);
};
SWFSlider.preloadSlide = function()
{
      var car = this.loader.getBytesLoaded();
      var tot = this.loader.getBytesTotal();
      if(car >= tot && tot > 4){
            clearInterval(this.intervalID);
            this.intervalID = setInterval(this, "fadeInSlide", 20);
      }
};
SWFSlider.fadeInSlide = function()
{
      if(this.loader._alpha < 100){
            this.loader._alpha++;
      } else {
            clearInterval(this.intervalID);
            this.intervalID = setInterval(this, "stopSlide", 5000);
      }
};
SWFSlider.stopSlide = function()
{
      clearInterval(this.intervalID);
      this.intervalID = setInterval(this, "fadeOutSlide", 20);
};
SWFSlider.fadeOutSlide = function()
{
      if(this.loader._alpha > 0){
            this.loader._alpha--;
      } else {
            clearInterval(this.intervalID);
            this.nextSlide();
      }
};

SWFSlider.init();
0
 
LVL 1

Author Comment

by:nickleplated
ID: 9822229
I have to say that is absolutetly beautiful!

just playing with it now ;)

N
0
 
LVL 1

Author Comment

by:nickleplated
ID: 9822239
Your example works perfectly!

Is it possible to have the first image load already faded in?


Can I also ask why, when I try to put the main welcome.swf into a different page, it loads the main, but not any of the other layers?
If I just look at it from the html file that flash generates, it loads everything fine.....

wtf?

N
0
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

 
LVL 27

Accepted Solution

by:
negatyve earned 500 total points
ID: 9822273
>I have to say that is absolutetly beautiful!

cheers, mate! :)

>when I try to put the main welcome.swf into a different page, it loads the main, but not any of the other layers?

ok, try to figure out this situation:

folder/welcome.html
folder/innerFolder/welcome.swf
folder/innerFolder/welcomeEvents.swf
folder/innerFolder/welcomeOnline.swf
folder/innerFolder/welcomeData.swf
folder/innerFolder/welcomeComm.swf

with welcome.swf embedded in welcome.html

when welcome.swf tries to load:

<item src="welcomeEvents.swf"     />

it cannot find it, because it uses the html page path, not the swf one. so, you should change your xml file to:

=======================================
<?xml version="1.0" encoding="UTF-8"?>
<slides>
    <item src="innerFolder/welcomeEvents.swf"     />
    <item src="innerFolder/welcomeOnline.swf"     />
    <item src="innerFolder/welcomeData.swf"     />
    <item src="innerFolder/welcomeComm.swf"     />
</slides>
========================================


>Is it possible to have the first image load already faded in?

yep. just change the old script with this one:

stop();
SWFSlider = {path:this};
SWFSlider.init = function()
{
      this.data_xml = new XML();
      this.data_xml.ignoreWhite = true;
      this.data_xml.path = this;
      this.data_xml.onLoad = function(success)
      {
            if(success){
                  this.path.initSlide();
            } else {
                  trace("XML FILE MISSING");
            }
      };
      this.data_xml.load("slides.xml");
};
SWFSlider.initSlide = function()
{
      var nodes = this.data_xml.firstChild.childNodes;
      this.slide_array = [];
      for(var i = 0; i < nodes.length; i++){
            this.slide_array.push(nodes[i].attributes["src"]);
      }
      this.curSlide = -1;
      this.maxSlide = this.slide_array.length;
      delete this.data_xml;
      this.loader = this.path.createEmptyMovieClip("pic_loader", 15000);
      this.nextSlide();
};
SWFSlider.nextSlide = function()
{
      if(this.curSlide < this.maxSlide - 1){
            this.curSlide++;
      } else {
            this.curSlide = 0;
      }
      this.loader.loadMovie(this.slide_array[this.curSlide]);
      clearInterval(this.intervalID);
      this.intervalID = setInterval(this, "preloadSlide", 20);
};
SWFSlider.preloadSlide = function()
{
      var car = this.loader.getBytesLoaded();
      var tot = this.loader.getBytesTotal();
      if(car >= tot && tot > 4){
            clearInterval(this.intervalID);
            this.intervalID = setInterval(this, "fadeInSlide", 20);
      }
};
SWFSlider.fadeInSlide = function()
{
      if(this.loader._alpha < 100){
            this.loader._alpha++;
      } else {
            clearInterval(this.intervalID);
            this.intervalID = setInterval(this, "stopSlide", 5000);
      }
};
SWFSlider.stopSlide = function()
{
      clearInterval(this.intervalID);
      this.intervalID = setInterval(this, "fadeOutSlide", 20);
};
SWFSlider.fadeOutSlide = function()
{
      if(this.loader._alpha > 0){
            this.loader._alpha--;
      } else {
            clearInterval(this.intervalID);
            this.loader.removeMovieClip();
            this.loader = this.path.createEmptyMovieClip("pic_loader", 15000);
            this.loader._alpha = 0;
            this.nextSlide();
      }
};
SWFSlider.init();
0
 
LVL 1

Author Comment

by:nickleplated
ID: 9822326
MMMMMMMM.....sooo nice.

C'Mon now...you mod'd that from something you already had done..... so nice, colour me very happy :)

I made the changes you suggested. As I also wanted to keep the xml file with the rest of the swfs, I changed the  this.data_xml.load("slides.xml"); line to reflect the 'inner folder' aswell...


working like a charm!

Cheers!
N
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9822343
>I made the changes you suggested. As I also wanted to keep the xml file
>with the rest of the swfs, I changed the  this.data_xml.load("slides.xml");

that's a good mod too, well done!

>C'Mon now...you mod'd that from something you already had done

I do swear on my name that I made it now from scratches.. :)

>working like a charm!

really glad you like it!

cheers!
0
 
LVL 1

Author Comment

by:nickleplated
ID: 9822372
just looking at your site > wishing there was an english version ( or that I could read italian!)

(just got married in Positano in October > love italy very much - driving in italy is one of my new favourite things!)

Thanx again,
N
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9824258
>just got married in Positano in October > love italy very much -

congratulations!! :)

>driving in italy is one of my new favourite things!)

ahhaha, you definetely like danger!! :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
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 how to load their YouTube profile onto Flash Media Live Encoder.
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.

757 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

19 Experts available now in Live!

Get 1:1 Help Now