|
||||||
|
||||||
Flash Tutorial - Communication between Flash Movies: Part 1

Free Flash Tutorial
Step Two: Creating the Second Flash Movie
Note: Do not use Instance Name, it is not the same as a variable name.

Your Property Inspector should look similar to this.
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();
}
};
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
|
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
|
|
|
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.
|