|
JavaScript can greatly extend the power and flexibility
of your Flash file. The following covers the Java/JavaScript interface
which operates in both directions:
- Flash calling JavaScript
Where the Flash file calls a JavaScript function in response to some
event such as a mouse click.
| JavaScript
calling Flash: |
1 Cool Menu FX Tool provides two areas of control
using JavaScript to affect a 1 Cool Menu FX Tool flash file. You can change
a button's visibility (hidden or visible) and the initial checked state
of a button.
Generated Code
When either of the JavaScript options are checked on the Advanced Options
dialog on the Output tab, 1 Cool Menu FX Tool will create the JavaScript
required to set the initial checked state or button visibility in a swf
file.
Example:
This is the automatically generated code for a 5 button menu. To change
a button's status to invisible, just change the "true" to "false"
in the code. You can delete all references to buttons you do not want
to change:
<SCRIPT LANGUAGE=Javascript>
<!--
var InternetExplorer = navigator.appName.indexOf("Microsoft")
!= -1;
// Change the initially visible
state of buttons by setting the
// variables below to "true" (visible) or "false"
(not visible)
var Button_1_visible = true;
var Button_2_visible = true;
var Button_3_visible = true;
var Button_4_visible = true;
var Button_5_visible = true;
function New_Project_1_DoFSCommand(command, args) {
var New_Project_1Obj = InternetExplorer ? New_Project_1 : document.New_Project_1;
if (command == 'setVisible') {
New_Project_1Obj.TSetProperty('/Button 1', 7, (Button_1_visible ? '1'
: '0'));
New_Project_1Obj.TSetProperty('/Button 2', 7, (Button_2_visible ? '1'
: '0'));
New_Project_1Obj.TSetProperty('/Button 3', 7, (Button_3_visible ? '1'
: '0'));
New_Project_1Obj.TSetProperty('/Button 4', 7, (Button_4_visible ? '1'
: '0'));
New_Project_1Obj.TSetProperty('/Button 5', 7, (Button_5_visible ? '1'
: '0'));
}
}
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
Sub New_Project_1_FSCommand(ByVal command, ByVal args)
call New_Project_1_DoFSCommand(command, args)
end sub
</SCRIPT>
Example:
If we wanted to make "Button_1" invisible we would change the
code to the following. Note: You can remove all references to other buttons.
<SCRIPT LANGUAGE=Javascript>
<!--
var InternetExplorer = navigator.appName.indexOf("Microsoft")
!= -1;
// Change the initially visible state
of buttons by setting the
// variables below to "true" (visible) or "false"
(not visible)
var Button_1_visible = false;
function New_Project_1_DoFSCommand(command,
args) {
var New_Project_1Obj = InternetExplorer ? New_Project_1 : document.New_Project_1;
if (command == 'setVisible') {
New_Project_1Obj.TSetProperty('/Button 1', 7, (Button_1_visible ? '1'
: '0'));
}
}
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
Sub 1logo_FSCommand(ByVal command, ByVal args)
call 1logo_DoFSCommand(command, args)
end sub
</SCRIPT>
Don't worry if you don't understand how it all works - all
of the code is automatically generated, all you have to do is change "true"
to "false" next to the appropriate button.
|
Flash calling JavaScript:
|
Your Flash file can call a JavaScript
function in two ways:
- By using a javascript: URL
When a button is clicked, and the
Link URL begins with "javascript:" a JavaScript function
will be called.
The syntax for a JavaScript URL is:
javascript:functionName([param1], [param2], ...);
Example:
The URL javascript:add(a, b); will call the function add
and pass the parameters a and b.
- By using a Call action
When some event happens (such as
entering a button) and a Call action is specified, a JavaScript
function will be called.
The syntax for a Call action is:
Call functionName([param1], [param2], ...)
Example:
The action Call add(a, b) will call the function add
and pass the parameters a and b.
|