TWiki
> Main
> HowToUseFlash >
HowControlMediascape
How do I Control the Mediascape from the Flash Movie?
It is possible to send notifications and data back to the Mediascape from within a Flash movie. For example, you may want to notify the mediascape when a particular Flash button on screen has been pressed, and then perform an action such as playing a sound in response.
This example will show how to achieve this effect.
- Download the example FLA file PressExample.fla and the Mediascape Flash Actionscript Library mediascape.as to the same folder on your computer.
- Open the FLA file in Flash.
- Click the large 'Press' button
- In the Actions Window (Window / Development Panels / Actions Panel), ensure the following code is inserted:
on (press)
{
fscommand("press");
}
This code uses the
fscommand method to send a message to the mediascape containing the word "press". The mediascape will receive a
OnFSCommand event on the Flash movie object carrying with it the data "press". The mediascape author can then choose to respond to this event by looking at the data and playing a sound in response.
- Publish the swf file (File / Publish)
Next we need to create the mediascape.
- Open Mediascape Editor
- Import an audio file by clicking the 'Audio' button on the toolbar. If you don't have an audio to hand, try this one.
- Add a Flash Player (right-click Media and select Add Flash Movies)
- A button labelled Flash will appear in the main toolbar. Click this button to import the swf that you have just published.
- Click on the newly-added flash object in the mediascape window (left-hand panel)
The script window (bottom-right panel) will list the event
OnFSCommand on your Flash movie object. This event will be triggered every time there is a fscommand() method in the flash movie.
- To respond to the fscommand from flash by playing a sound add the following code
if (Command == "press")
{
myAudio.Play();
}
(where myAudio is the name of the audio you just imported)
You can insert as many calls to
fscommand() in your Flash actionscript as you want, for example you can have many buttons that send different commands. All of these commands will end up in the same place in the mediascape - the
OnFSCommand event. In order to differentiate between the different commands in the mediascape you should add
if blocks to your mediascape
OnFSCommand code for each possible command.
For example:
if (Command == "Press")
{
myAudio.Play();
}
if (Command == "Pause")
{
myAudio.Pause();
}
if (Command == "Exit")
{
goodbyeImage.Show();
}