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

Free Flash / JavaScript Tutorial
![]()
This tutorial shows you how to send information between different Flash Movies in different Windows (different web pages) such as: Pop Up Windows or other web pages. Theoretically there is no limit to what information can be sent between each Flash Movie, and you can control a Flash Movie on another web page, from your main movie on your main page.
Note: This is part 2 of this tutorial. You can do part 2 without looking at part 1, but the ActionScript is explained in detail in part 1. This tutorial is different from part 1, as it uses JavaScript to control the different Windows or web pages.
Cross Ref: There is another tutorial specifically on how to create Pop Up Windows with Flash. Having said that both techniques work fine, although the technique listed here has more flexibility such as having a close Pop Up button: Pop Up tutorial
Example: Download the Flash file Int 122a
Example of opening pop up windows and then closing them by sending information between Flash Movies.
Step One: Creating the Controller Movie
This is the Movie that you will use to control the other Movies.
on (press) {
_root.sender.send("myConnection", "doAction", 2);
} on (release) {
getURL("javascript:NewWindow=window.open ('pop1.html', 'myWindow', 'width=468, height=60, left=400, top=200, toolbar=No, location=No, scrollbars=No, status=No, resizable=No, fullscreen=No'); NewWindow.focus(); void(0);");//Note from getURL to here is all one line
}
Note: pop1.html is the name of the web page that will be opened. The size of the page will be 468 x 60 pixels. The left=400, top=200 is the position on screen of the Pop Up Window.
on (press) {
_root.sender.send("myConnection", "doAction", 2);
}
on (release) {
getURL("javascript:NewWindow=window.open('pop2.html', 'myWindow', 'width=70, height=70, left=400, top=200, toolbar=No, location=No, scrollbars=No, status=No, resizable=No, fullscreen=No'); NewWindow.focus(); void(0);");//Note from getURL to here is all one line
}
Note: pop2.html is the name of the web page that will be opened. The size of the page will be 70 x 70 pixels.
on (release) {
_root.sender.send("myConnection", "doAction", 2);
}
Note: This closes any of the Pop Up Windows that the other buttons may have opened.
sender = new LocalConnection();
Step Two: Creating the Second Flash Movie - Pop Up 1
Cross Reference: If you do not know how to make a simple animation, there are several animation tutorials in the beginners section such as: Tweening
receiver = new LocalConnection();
receiver.doAction = function(doThat) {
if (doThat == 2) {
getURL("javascript:self.close();");
}
};
receiver.connect("myConnection");
Step Three: Creating the Third Flash Movie - Pop Up 2
receiver = new LocalConnection();
receiver.doAction = function(doThat) {
if (doThat == 2) {
getURL("javascript:self.close();");
}
};
receiver.connect("myConnection");
Step Four: Creating the Web Page - Sender
You need to create three web pages. One for the controller / sender page, and another two: one for each of the Pop Up Movies. There is nothing special about the code that follows and you do not need to code it by hand. If you have Dreamweaver or another web editor, you can create you web pages in your editor and just drag the Flash Movie (swf file) onto the page.
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="550" HEIGHT="400" id="sender" ALIGN="">
<PARAM NAME=movie VALUE="sender.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="sender.swf" quality=high bgcolor=#FFFFFF WIDTH="550" HEIGHT="400" NAME="sender" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
Note: sender.swf is the name of the Flash Movie that sends the info to the other Movies and the size of the Movie will be 550 x 400 pixels.
Step Five: Creating the Web Page - Pop 1
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="468" HEIGHT="60" id="pop1" ALIGN="">
<PARAM NAME=movie VALUE="pop1.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FF0000>
<EMBED src="pop1.swf" quality=high bgcolor=#FF0000 WIDTH="468" HEIGHT="60" NAME="pop1" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
Note: pop1.swf is the name of the Flash Movie that will open in this page and the size of the Movie will be 468 x 60 pixels.
Step Six: Creating the Web Page - Pop 2
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="70" HEIGHT="70" id="pop2" ALIGN="">
<PARAM NAME=movie VALUE="pop2.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFDC5A>
<EMBED src="pop2.swf" quality=high bgcolor=#FFDC5A WIDTH="70" HEIGHT="70" NAME="pop2" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
Now although opening and closing Pop Up Windows may not seem amazing, it illustrates how you can run commands and send information to and from different Flash Movies. These flash movies can be on the same page or on different pages. You can use this example and modify it to run any function or pass any information between Flash Movies. It is highly adaptable and versatile and is simple to use. It seems to work no matter where you put the flash movies.
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.
|