\n'); } //-->
|
||||||
|
||||||
Flash Tutorial - FS Commands

Free Flash Tutorial
to FS Commands
The aim of the tutorial is to learn how to get Flash to send the Browser JavaScript commands. You will learn how Flash can be used to run JavaScript code on a HTML web page. This is called an FS Command.
Example: Download the Flash file Int 118a
| Start Up Message |
Example of Flash buttons that run JavaScript commands on the web page.
Note: Some of the above JavaScript commands can be done directly from Flash: Pop Ups, Random page and Print.
In my opinion it is better, when possible, to use Flash directly. The reason for this is because Internet Explorer and Netscape interprets JavaScript differently, therefore you get Browser inconsistency. You will also find that different versions of the Browsers will vary, this makes testing difficult. In general in Flash if something works it will work irrespective of what Browser you are using.You will find that all of the above JavaScript has been designed to work in Internet Explorer.
Step One: The Flash Buttons
Note: You must always start at "0" and keep going up in number by "1" each time you add the code to a new button.
Step Two: The JavaScript
Note: You MUST use this code or the FSCommand will not work !!
Note: The Flash movie that you created earlier (the swf file) must be in the same location as your web page. If it is in the same location as the web page then you only use the button name. If however the file is in a different location you must include the file path. If you don't know about HTML file paths just make sure your Flash Movie is located in the same folder as your web page.
JavaScript Functions Used in this Tutorial
In the example above all individual JavaScript functions are in the Head tag except for one. The message that is displayed needs a small amount of additional information in the Body of the web page. Otherwise the Browser would not know where to display the message:
<a id="Words">You can add a start up message here that will show up when the page first loads.</a>
The following is the Java Script functions as listed in the head tag of this page:
<script language="javascript" type="text/javascript">
<!--// LINKS FOR RANDOM FUNCTION
var links = new Array(4);
links[0] = "http://www.yahoo.com/";
links[1] = "http://www.google.com/";
links[2] = "http://www.altavista.com/";
links[3] = "http://www.webcrawler.com/";
// Handle all the FSCommand messages in a Flash movie
function navbar_DoFSCommand(command, args) {
if ( command == "0" ) {
if ( args == "click" ) { }
if ( args == "over") {
Words.innerHTML = 'This button will display a message on the browser status bar.';
self.status="Hey this is a very long status bar message !";
}
if ( args == "out" ) {
self.status="";
Words.innerHTML = 'Start Up Message';
}
}
if ( command == "1" ) {
if ( args == "click" ) { openWindow('http://www.yahoo.com',350, 295); }
if ( args == "over") { Words.innerHTML = 'This will open Yahoo website in a popup window'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "2" ) {
if ( args == "click" ) { }
if ( args == "over") { Words.innerHTML = 'This button will only display a message here on MouseOver'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "3" ) {
if ( args == "click" ) { }
if ( args == "over") { Words.innerHTML = '<img src=\"wasp.jpg\"><P>You can display images too'; }
// CHANGE THE ABOVE IMAGE SRC TO YOUR OWN E.G. YourImage.GIF
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "4" ) {
if ( args == "click" ) { shake(10); }
if ( args == "over") { Words.innerHTML = 'Click for the EARTH QUAKE !'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "5" ) {
if ( args == "click" ) { window.external.AddFavorite('http://www.webwasp.co.uk/','webwasp.co.uk') }
if ( args == "over") { Words.innerHTML = 'Add webwasp.co.uk to your favourites !'; }
// Change the above web address to your own
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "6" ) {
if ( args == "click" ) { alert ("This is a Javascript Alert") }
if ( args == "over") { Words.innerHTML = 'Click this button to generate an \'Alert\' message'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "7" ) {
if ( args == "click" ) { random(); }
if ( args == "over") { Words.innerHTML = 'Click this button to randomly go to Yahoo, Google, AltaVista or WebCrawler'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "8" ) {
if ( args == "click" ) { history.go(-1); }
if ( args == "over") { Words.innerHTML = 'This button will act like your browser\'s back button'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "9" ) {
if ( args == "click" ) { window.print(); }
if ( args == "over") { Words.innerHTML = 'Click this button to bring up the print prompt box'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
if ( command == "10" ) {
if ( args == "click" ) { top.window.close(); }
if ( args == "over") { Words.innerHTML = 'Click button to close this window'; }
if ( args == "out" ) { Words.innerHTML = 'Start Up Message'; }
}
}// EARTHQUAKE FUNCTION
function shake(n) {
if (self.moveBy) {
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {
self.moveBy(0,i);
self.moveBy(i,0);
self.moveBy(0,-i);
self.moveBy(-i,0);
}
}
}
}function openWindow(file,w,h) {
newWindow = window.open(
file,
'newWin',
'top=100,left=150,width='+w+',height='+h+',resizable=yes,toolbar=no,location=no,scrollbars=yes')
}function random() {
var a = 1+Math.round(Math.random()*4);
var i = a;
location = links[i];
}
function expand() {
for(x = 0; x < 50; x++) {
window.moveTo(screen.availWidth * -(x - 50) / 100, screen.availHeight * -(x - 50) / 100);
window.resizeTo(screen.availWidth * x / 50, screen.availHeight * x / 50);
}
window.moveTo(0,0);
window.resizeTo(screen.availWidth, screen.availHeight);
}//-->
</SCRIPT>
Further Info about JavaScript
For more information on what JavaScript is and tutorials on how to use it simply
go to google and search for “JavaScript” or “JavaScript
tutorials”. If you simply spend some time searching the net you'll
soon find many sites that give help and advice tutorials on JavaScript
for example:
http://www.hotscripts.com
http://www.experts-exchange.com
http://forums.devshed.com/
http://www.allexperts.com
http://javascript.internet.com/
http://www.javascript.com/
For more help and advice please feel free to ask for help on the webwasp massage boards: forum
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.
|