Flash / AS

Silverlight

WPF

ASP.net / PHP

Photoshop

Forums

Blog

About

 


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

 

 

 

 

 
Loading Techniques: Flash 5 & Flash MX
         written by ilyas usal a.k.a. pom

There are two ways of loading movies with Flash:

  • loading into target
  • loading into level
Loading into target was explained by Kirupa in this tutorial, that's why I won't talk at all about it here. We'll see how to load into target with Flash (5 or MX, it's the same), and then how to load dynamically with Flash MX.

 

[ simple enough, but you get the idea ]

 

Navigation:
Use the following links to navigate through this tutorial:



Loading movies into target: Flash 5

  1. What we need is simple : a button to launch the load, an empty clip to load the movie in, and a .swf file (called loaded.swf), in the same folder as the present movie.
     
    I suppose you know how to create a button. To create rapidly an empty movie clip, press Ctrl+F8, name it 'container', then click the Scene 1 vignette above the timeline. Now open the library with Ctrl+L and drag and drop the movie clip on a new layer of your scene.
     
  2. u need to give this movie clip the instance name 'container' (without the '). On your scene, you should have nothing but a button and an empty movie clip. The rest is code. Select the button, and open the Actions Panel. Click the '+', select Basic Actions and then Load Movie. The scene should look like this:

[ For the moment, we're loading into level ]
 

  1. Select the line that says loadMovieNum, and enter this :
    URL : loaded.swf
    Location : Target container
    Variables : Don't send
     
  2. How does this work ?
    URL is the movie you want to load. Here, it's loaded.swf. When you go online, you'll have to put the absolute path here, or it won't work.

    Location : target tells Flash that you're loading into target. The following field is the target. When you load into level, you put the level here, here we put the target movie clip (which is not an expression) container.

    The line should read : loadMovie ("loaded.swf", "container");

Loading movies into target: Flash MX

  1. Put a button on your scene, and give it the instance name but in the Property Panel. Create a new layer in your movie and name it code
     
  2. Now add this code to the first frame of the code layer:

Explanation of the Code:

but.onPress = function () {
We define the behaviour of the button as a callback function in the _root. rather than in the button itself here. We could have done it normally, of course, with a simple on (press) handler.

_root.createEmptyMovieClip("container", 1);
Instead of creating an empty movie and putting it on the scene, we do it with Actionscript. Here, we create an empty movie clip in the _root., named container and located in _level1.

loadMovie("loaded.swf", "container");
Exact same line as in Flash 5.

container._x = 150 ;
We set the position of the clip.

As you can see, it's much quicker here, thanks especially to the new createEmptyMovieClip function. AND the movie clip is very easy to handle afterwards, as we'll see in the next part.

 


Loading .jpg dynamically with Flash MX:
This is one of the most awaited new feature of Flash MX. So far, it was impossible to load dynamically images and sounds without application such as Generator or Ming. Well, it's now possible (and easy), which makes Flash a wonderful tool to build dynamic sites.

First of all, be careful : Flash MX allows you to load dynamically images that are non-progressive JPEG. Save the images you want to load under this format, in RVB mode and everything will be just fine.

[ this picture has been loaded dynamically ]

Actually, it's exactly the same as previously. All you have to do is replace loaded.swf by any .jpg you want.

As I said, the other advantage of this method is that you can very easily manipulate what you've just loaded. For instance, if we want to make draggable the image we loaded, all we have to do is to write in the first frame of the layer code:


Load .mp3 dynamically with Flash MX:
It's the same method. The commands change a bit, but the idea is similar : you create an instance of a sound object, in which you load the sound. This instance is what we will use to change the properties of the sound (volume for instance).
 
Here again, you can load dynamically sounds under a certain format, which happens to be MP3.

mySound = new Sound();
You create a new Sound object.

mySound.loadSound("music.mp3",true);
You load music.mp3 into mySound. The second parameter is call isStreaming. If it's set to true, the sound will play while loading, whereas it will wait until it's fully loaded before playing if isStreaming is set to false.

There ! You have just completed this tutorial. I have provided the source code to the animations so that you can compare your fla to mine. Click the Download FLA link below to download the source file:

Download All Source Files

I hope the information helped. If you have any questions or comments, please don't hesitate to post them on the Message Board. I should be there, along with others flashers to help you.

pom 0]

 




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.