|
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 Button Tool provides two areas of control
using JavaScript to affect a 1 Cool Button 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 Build Flash Tab,
1CBT will create the JavaScript required to set the initial checked state
or button visibility in a swf file - this is useful when using the same
Flash file on several HTML pages or in a frameset as in the case of a
navigation scheme.
Example:
This is the automatically generated code for the example file 1logo.1cb.
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 One_visible = true;
var Button_visible = true;
var Cool_visible = true;
var Tool_visible = true;
var tulip_1_visible = true;
var Easy_visible = true;
function 1logo_DoFSCommand(command,
args) {
var 1logoObj = InternetExplorer ? 1logo : document.1logo;
if (command == 'setVisible') {
1logoObj.TSetProperty('/One', 7, (One_visible ? '1' : '0'));
1logoObj.TSetProperty('/Button', 7, (Button_visible ? '1' : '0'));
1logoObj.TSetProperty('/Cool', 7, (Cool_visible ? '1' : '0'));
1logoObj.TSetProperty('/Tool', 7, (Tool_visible ? '1' : '0'));
1logoObj.TSetProperty('/tulip_1', 7, (tulip_1_visible ? '1' : '0'));
1logoObj.TSetProperty('/Easy', 7, (Easy_visible ? '1' : '0'));
}
}
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
Sub 1logo_FSCommand(ByVal command, ByVal args)
call 1logo_DoFSCommand(command, args)
end sub
</SCRIPT>
Example:
If we wanted to make the Tulip invisible we would change the code to the
following, note we have removed 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 tulip_1_visible = false;
function 1logo_DoFSCommand(command,
args) {
var 1logoObj = InternetExplorer ? 1logo : document.1logo;
if (command == 'setVisible') {
1logoObj.TSetProperty('/tulip_1', 7, (tulip_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 1CBT 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.
|