Communicate: Flash Movies

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Communication between Flash Movies: Part 1

 

Free Flash Tutorial


Step 2    <<   Previous      Intro   1   2   3     Next   >>       >>   Webwasp Mates

 

Step Two: Creating the Second Flash Movie

  1. Open a new: Flash Movie
  2. Make the Document Size: 80 x 80 pixels
    You can do this in: Modify > Document
  3. Using the Text Tool drag out a small: Text Box
  4. In the Property Inspector set the Text Box as: Dynamic Text
  5. Give the Text Box a Variable name: displayNumber

    Note: Do not use Instance Name, it is not the same as a variable name.


    Your Property Inspector should look similar to this.

  6. Using the Text Tool type under the Text box the Label: Frame Number
  7. As the previous Text Box was set to Dynamic Text you will probably see that the new text (Frame Number) is also set to Dynamic text, make sure you go to the Property Inspector and reset it to: Static text
  8. Add this code to the first frame of the Movie:
  9. onEnterFrame = function () {
        _root.displayNumber = _root._currentframe;
    };

    myReceiver = new LocalConnection();
    myReceiver.connect("myConnections");
    myReceiver.myAction = function(doThis) {
        if (doThis == 1) {
            play();
        } else if (doThis == 2) {
            stop();
        }
    };

  10. Go to frame 50 in the Timeline and right click (Mac: Ctrl click) and select: Insert Frame
  11. Test your Movie: Control > Test Movie (Short Cut Key: Ctrl + Enter)

    You should find that the Text Box displays the current frame number like this:


    Frame numbers being displayed as the Movie plays.

  12. Save your file as: movie_2.fla
  13. Now Export you Movie as a Flash Movie (swf file): File > Export > Export Movie
    This will create a file called: movie_2.swf


The ActionScript Explained

The code below displays the current frame number. It sends the frame number to the Dynamic Text Box that is on stage. The only reason for this is so that you can see if the Movie is Playing or not.

onEnterFrame
= function () {
    _root.displayNumber = _root._currentframe;
};


It is the function below that does all the work. If Movie 1 sends a parameter (the numbers 1 or 2) it does the appropriate action. In this case either: play or stop

myReceiver = new LocalConnection();
myReceiver.connect("myConnections");
myReceiver.myAction = function(doThis) {
    if (doThis == 1) {
        play();
    } else if (doThis == 2) {
        stop();
    }
};


If you wanted additional actions you would add the extra action like this:


myReceiver = new LocalConnection();
myReceiver.connect("myConnections");
myReceiver.myAction = function(doThis) {
if (doThis == 1) {
        play();
    } else if (doThis == 2) {
        stop();

    
} else if (doThis == 3) {
        do some other action;
    
}
};

If you wanted two way communication between Flash Movies like in the second example (see example: Int121b) at the top of this page, you need to edit the code. Each time you use the code you would need to change all the variable names otherwise chaos will ensue! You would do this like this:


//code coming from Movie 1
myReceiver
_1 = new LocalConnection();
myReceiver
_1.connect("myConnection_1");
myReceiver
_1.doAction_1 = function(doThat_1) {
if (doThat
_1 == 1) {
play();
} else if (doThat
_1 == 2) {
stop();
}
};

//code going to Movie 2
mysender_2 = new LocalConnection();

If you find this confusing download the example files Int121b and look how the variable names have been changed. Remember to look in both the buttons and the Timeline: Download Flash Samples

         

Step 2    <<   Previous      Intro   1   2   3     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.