Support Articles for the CommandSim Environment
Glossary    Contact Us
Browse by Category
CommandSim > Scenario Design > How to show/hide a broken window

How to show/hide a broken window

In the course of mitigating the incident, your responders may open doors and break windows.  You can show this effect using environment variables in the same way as the instructions relate in "How to embed a victim in a node/location".  That article gives the background information about environment variables, as well as the article "Adding Environment or Participant Variables".

As a follow-on to this article, if you want to show or hide smoke as a result of breaking the window, see our article "How to Change the State Programmatically."

Essential Idea

The essential elements you will need to add a broken window are:

  1. A picture of the location with the window intact
  2. A picture of the window broken
  3. An environment variable that will say whether the window is intact or broken.

Pictures typically come out of digital cameras at a high resolution, at least 180 or 300 dpi, and often more than 1000 pixels wide.  For screen rendering, you can reduce the dpi to 72, and the overall size (for a picture filling the whole screen) to 640x480.  You should reduce your broken window picture (item #2, above) by the same proportion as you reduce the node/location photo.

Note: You can resize the image inside of Flash, but that does not reduce the picture's dpi--it only scales the photo down.  This means the photo still takes up the larger space.  Larger space is not bad in itself, but it then requires more bandwith to transmit around your network, so there can be loading delays.  Therefore, we recommend smaller sizes.

The essential idea is to create a Movie Clip with your broken window picture, and create an environment variable to hold the status of the clip as visible or invisible.  Then you will add code to check the status of the variable when the movie first loads, as well as hook up a routine that detects when the value changes -- and you will tell the broken window clip to show or hide itself, depending on the value.


The steps are:

  1. Place your node photo at the bottommost layer of your movie.
  2. On a higher layer you will import your broken window graphic.  Position the broken window exactly in the place you want it to appear, covering the intact window.
  3. Then, by choosing Modify > Convert to Symbol... (with the broken window selected), you convert it into a Movie Clip -- this allows it to be given an (instance) name to which we can refer (so we can write code to tell that instance to show or hide itself).
  4. Now give this instance an Instance Name (for example, "broken1").
  5. Create a new layer to hold the code that will tell the broken window to turn on or off.
  6. Open the Actions panel and enter the following code into the panel:

function eVarValChg (id, val) {
  if (id == "WINDOW1" && val == "true") {

    broken1._visible = true;
  } else if (id == "WINDOW1" && val == "false") {
    broken1._visible = false;


var win1Val = _parent._parent.getEnvironVar("WINDOW1");
if (win1Val == "true") {
   broken1._visible = true;
} else {
   broken1._visible = false;

There are two blocks of code to explain.  In the first block, the code that begins with function eVarValChg defines a routine that CommandSim knows to call if an environment variable changes (for example, the instructor sets the value of a variable).  Whenever a variable changes, the variable name (the message) is passed in as id and as well as the new value (val).  The next line checks to see if the message is WINDOW1, which will be the name of our environment variable.  If it is, then the routine sets the visibility of the broken window Movie Clip to visible (true) or invisible (false), depending on whether the value coming in is true or false.

The second block is an instruction to execute when the movie first loads.  Instead of waiting to be told the value of WINDOW1, it queries CommandSim for the value, and based on the value, it sets the broken window MovieClip to visible or invisible.

The preceding steps have taken care of all the things we need to do in the node's Flash file.  Now we have to add the environment variable WINDOW1 to our scenario definition.

The simplest way is to open the Scenario Designer tool and choose the STATES & VARIABLES tab.  In this tab on the top right is an area in which you can create or modify environment variables.  When you click to add an environment variable, it will ask you for the name (which is what instructors see, and may have spaces), the id (in our example, WINDOW1) which cannot have spaces, and the starting value.  Type in a name, type in WINDOW1 for the id, and make the starting value false if you want the broken window to be invisible by default, or true if you want to start the scenario with the window broken already.

Once you save your scenario file, and then use the ServerFilePrep tool to package it into a form for the server, you are all done.  When you load the instructor panel next, you should see your environment variable in the STATES & VARIABLES tab on the instructor panel.  If you click the name, the current value will appear in the box below.  You can enter the new value (true or false), then press the Do It button.  The clock must be running (not paused) for the new value to take effect.

Note: if you prefer to make the change directly in the scenario XML file (without using the Scenario Designer), you can add the following to your scenario definition file, replacing the line that reads


     <environVar value="false" id="WINDOW1" name="broken window 1"/>

We strongly urge you to make a backup copy of the scenario definition file before you edit it, in case you enter an incorrect character or accidentally delete something important.  Flash is unforgiving with errors in XML files.

For an example of this, you can use the example file from the article "How to embed a victim in a node/location".


How helpful was this article to you?

Related Articles

powered by Lore
Copyright 2004-11, Equipment Simulations LLC, all rights reservered.