Flash Components      Flash Menu      Flash Gallery      Flash Slideshow      FLV Player      Flash Form      MP3 Player      PhotoFlow      Flash CMS      3D Wall      Flash Scroller

Flash / AS

Silverlight

WPF

ASP.net / PHP

Photoshop

Forums

Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

 

 

 
Loading
a Random Background - Page 2
         written by kirupa chinnathambi

Now that we finished adding the movie clip, your movie clip should look like a hollow circle:

[ the empty movie clip should look like a hollow circle ]

Let's continue on with the rest of the steps:

  1. Select the movie clip (the hollow circle). The Properties panel will update itself to display information about the movie clip. You will see the W:, H:, X:, and Y: labels in the Properties panel. Enter a zero in each of the four fields:

[ enter a zero in the w, h, x, and y fields in the movie clip's properties ]

  1. Once you entered zeros in the four fields, you will notice the movie clip align perfectly on the top-left corner of your scene. Select the movie clip again, and give it the instance name location:

[ give an instance name to the movie clip (hollow circle) ]
 

  1. Now, look at your timeline. Right click on a blank keyframe in the timeline and select Actions. Copy and paste the following code:

[ copy and paste the above code in a blank keyframe of your movie ]

  1. Test the movie by going to File | Preview in Browser. Notice how the background randomly loads. You have just created an animation with a randomly loading background!
     
  2. You are done with this tutorial. If you are interested in learning more about this animation, read on. The final source code has also been provided for you to refer to. 

Frequently Asked Questions
I have compiled a list of questions people have asked regarding this effect, and I have provided my answers to those questions.

  • What if I want to load the images from a URL?
     
    • There is no difference between loading the background from a place on your hard drive or from the internet. In your code, where you see the lines image0.swf, image1.swf, etc. replace them with the path of your image. For example:

      location.loadMovie("http://www.kirupa.com/image1.swf");
  • Instead of having the background load automatically when the animation loads, I want the background to load when a visitor presses a certain button.
     
    • To make that happen, you will need to delete the code you entered into a blank keyframe. Once you have deleted the code, right click on the button that will be used for loading a background and select Actions. Use the following code for loading a random movie using a button:

You are using the exact same code as the one you used in the tutorial, but the above code has the button's on (release) handler to ensure that the code works when the user clicks on the button.

  • Are there other methods of achieving this effect?
     
    • Absolutely! In this tutorial, I tried to present the concept in a simplistic way. The code is not optimized for best performance, and nor is the tutorial comprehensive in all that is possible. Just understand how to use the loadMovie function to load an external SWF file into a movie clip.

      You can use any method of determining a random number and calling a movie (background) from another location and loading them into a movie clip. You could have used: if/else or even straight out concatenation with the base name of the movie plus the number ie:
      "http://www.kirupa.com/image" + var + ".swf";

This concludes this version of the tutorial. Click the download source link below to download the final source code for this tutorial:

download source

I hope the information helped. If you have any questions or comments, please don't hesitate to post them on the kirupa.com Forums. Just post your question and I, or our friendly forum helpers, will help answer it.

The following is a list of related tutorial and help resources that you may find useful:

How to use the Forums
New, Upcoming, and In-Progress Tutorials
How to Help out kirupa.com
Writing Tutorials
 
Cheers!
Kirupa Chinnathambi
kirupaBlog

 


Previous Page

Discuss on kirupaforum.com

 


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components
flash menus, buttons and components Digicrafts Components
The best flash components ever! Entheos Flash Website Templates
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
flash components Free Website | Make a Website
Learn how to advertise on kirupa.com