Environment communication
JavaScript messaging
It even possible to communicate to HTML page from Flash object which is embedded into it. This method is using JavaScript language, but Flash provides designer with wizard which makes a big part of work for you. Still you need to add some code not only to the Flash file but also manually change HTML file
- Create a file with two buttons on the stage and two input textboxes. Assign to them variable names "background" and "message"
- Add the following code to the buttons.
on(release) { fscommand("background", thecolor) } //and for second button on(release) { fscommand("message", themessage) } - Open Publish settings and change the top combo-box to Publish as Flash with FSCommangs. Publish the movie.
- Find the HTML file, that is created during publishing and view it's source code. In Internet Explorer you will need use View-Source menu.
At the top of the page you'll see the following code, it is embraced in SCRIPT tags.
function ex2_DoFSCommand(command, args) { var ex2Obj = InternetExplorer ? ex2 : document.ex2; // // Enter your code here // } - Modify this code. Instead comments //Enter your code here insert
this lines. Be sure to delete // symbol ! It is used for the comments.
if (command == "background") { document.body.style.backgroundColor=args; } if (command == "message") { window.alert(args); } - Save the code and refresh HTML file. At this step you may wish to open Publish Settings in Flash and disable HTML publishing because if you re-publish the file your custom HTML code will be wiped out.
- Enter various messages – they should pop up in the message box. Enter name of the colour (HTML named colours include practically all colours – like maroon, thistle, ivory, navy, lavender, khaki and even navajowhite. If you are familiar with JavaScript and HTML Document Object Model you may experiment with this code. But it's the realm of JavaScript.
\n'); } //-->