Mscape Help


How do I control the Flash movie from within my mediascape?

Flash movies allow mediascapes to have a graphically-rich animated UI. In order for this UI to be truely There are two parts to this. Creating the Flash movie to include in the mediscape, and then calling functions in the mediscape to control the Flash movie.

Create a Flash movie

HELP See Creating a Flash Movie for mscape for a step-by-step guide on how to make Flash movies that are suitable for use in a mediascape.

Include the standard mediascape library

Once you have created your flash move, in order to allow the Flash movie and your mediascape to communicate with one another, you need to add the mediascape ActionScript library.

Click the first frame of your movie, and bring up the Action editor (F9). Add the following:

#include "mediascape2.as"

tip Make sure that the file 'mediascape2.as' is available in the same directory as your Flash file so that it can be included.

Write ActionScript functions

For each action that you want the flash movie to be able to perform, you'll need to write an ActionScript method.

For example, you may have a Flash Movie that shows a welcome page on frame 1, and an animated sequence of a monster on frame 7. When your user walks into a region, you want the animation to begin. To achieve this, you'll need to write an ActionScript function that jumps to frame 7 - this function should go under the #include "mediascape2.as" line that you've already added.

function StartAnimation(){
   gotoAndPlay(7);
}

Calling the functions from your mediascape

From the mediascape you need to call this function you have defined above.

Firstly though you need to actually get the Flash movie running so that it will appear on the screen of the mobile device and react when you call the functions.

In the script for the 'OnLoad' event for the mediascape (the script that is run when the mediascape first starts up) you need to add the line:

myflash.Play();

(Where myflash is the name of your flash movie)

You can type this in or you can drag the Flash file from the left-hand panel and drop it in the script window then type a dot to get the possible completions.

Now you need to call the Flash function. You do this in response to some event. For example you could create a region and select it to show the script for the ‘OnEnter’ event in the script window (bottom-right panel).

Once again type this line in or drag and drop your Flash movie from the left-hand panel to the script window and it will put the name there. If you now type a full-stop (a period) after the name a menu will pop-up showing the possible completions. Select ‘RunActionScript’ (you have to double click) and you will have the following line in the script:

myflash.RunActionScript(name);

The 'name' bit needs to be changed into the name of the function that you want to call. Like this:

myflash.RunActionScript("StartAnimation")

Now, when this particular mediascape event is triggered, this bit of code will run the function in the Flash movie.

Passing data from the mediascape to the Flash movie

This is a similar process to that above, the main difference being that the function in the Flash movie needs to accept arguments and the function in the mediascape that calls it must pass it those arguments.

For example if we had a function in the Flash movie that displayed a score and it was declared like this:

function ShowScore(sc){
   scoreDisplay = Number(sc);  // ensure that sc is read as a number (see 'important note' below)
}

Then, in the mediascape we would need to call this function and pass it the argument like this:

myflash.RunActionScriptWithParams("ShowScore", 150);

Note that we are using RunActionScriptWithParams instead of RunActionScript and that we use the name of the function and the parameter that we are passing. The more parameters the function accepts the more we put in the statement to call it from the mediascape.

Important Note : All pieces of data passed from the mediascape to flash are passed as strings, e.g. pieces of text. This will usually cause no problems as flash should intelligently convert those strings into numbers if and when required. However in some cases you may get unexpected results.

function AddScore(sc)
{
    currentScore = sc + 10;  // this may NOT work, do not use!
}

In the above example, if currentScore is a 100 and the function AddScore is called with sc set to 10, currentScore may be set to 10010 rather than 110. This is because Flash may decide that you want to concatenate the text strings "100" and "10" together, giving "10010", rather than adding them together numerically.

To ensure it will always work, surround uses of any numeric parameters to functions called directly by the mediascape with the Number() function.

function AddScore(sc)
{
     currentScore = Number(sc) + 10; // This is the correct way
}

Controlling the mediascape from Flash

It is also possible to control the mediascape from within the flash movie. For example, you may want to have buttons in your flash movie that affect the mediascape - perhaps playing an audio or loading a new flash movie.

Follow the link below for more details on this topic.

HELP How do I control my mediascape from the Flash movie?

Ready to
get started?

Download Mscape Suite Version 2.1 | 10.5 MB

Download Mscape Beta

Experimental Beta Version 2.5 | 10.5 MB

Ask the Mscape Community

Forums