[Note: This article is very similar to the article about embedding a victim in a location. The difference is that this article shows how the participant can click to open or close the door, and hence the door must be a Button instead of a Movie Clip. The article is also similar to How to show/hide a broken window.]
As you create scenarios beyond the basic functionality, you may want to make them more realistic by requiring participants to open or close doors manually. Perhaps a participant shouldn't open a door, bringing in smoke or fire, but you want to give them that option. This
article answers the question of how to make a door appear open or closed, using an environment variable to
determine the door position.
What
is an Environment Variable?
An
Environment variable is a mechanism to record the position or value of
something, which the Flash movies can query to determine what to draw,
or how to react. For example, suppose you want to create a door that
can be open or closed. When the first responder sees the door, you want
it to start closed. When the responder opens the door, you want to
open that door and then any subsequent responder at that location should
see an open door. Therefore, you need a mechanism to record the value
of the door position -- open or closed.
Therefore, an environment variable records the position of
something, and then the Flash movie, before it draws the screen, can
request to see that value. You program your Flash movie at the node to
draw one thing if the value is "door is open", and another thing if the
value is "door closed".
Environment
variables enable powerful ways to make scenarios dynamically-responsive
to participant interaction. You can make as many environment variables
as you would like, and you can follow the procedure here or in other articles to have your Flash
movie listen to changes in the variables and set the variables.
Whereas there is only one value for each
environment variable, you can make a separate variable for each
responder by using participant variables. One good example of a
participant variable is remaining air in the responder's air pack.
Each responder has a different variable, reflecting the amount of air
time that responder has left. This article will not describe
participant variables, but the ideas in how to apply them are very
similar (see Adding
Environment or Participant Variables to learn
how to set and read participant variables).
Essential
Idea
The essential elements you will
need to make a door open and closed are:
- a picture of the node/location with the door open
- a picture of the node/location with the door closed
- an environment variable
that will say whether or not the door is open.
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 victim 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 door closed visual, and create an environment variable to hold the
status of that door as visible (meaning the door is closed) or invisible (meaning the door open picture will show). 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.
Steps
The steps are:
- Place your open door node photo at the bottommost layer of
your movie.
- Create a new layer and bring in a navigation arrow. The navigation arrow will be hidden by the closed door when the door is closed, and when the person opens the door, it will be revealed. Give the arrow an instance name by opening the Properties window when the arrow is selected, and entering the name "forwardarrow" in the box marked <Instance Name>.
- Create a new (higher) layer and import your closed door graphic (File > Import to Stage). Position the door closed graphic so it hides the door open graphic and the navigation arrow.
- On the same layer of the door closed graphic, you may want to add some text saying "click to open", or something to let the participant know he or she can open that door.
- Select the layer with the closed door graphic (step 3) and any text (step 4), choose the menu Modify > Convert to Symbol.... This converts your closed door graphic and text
into a Button -- 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), and it will provide the hooks so that it can be clicked on (to open the door)
- Now give this instance
an Instance Name (for example, "door").
- Create a new layer to hold the code that will tell
the victim to turn on or off.
- Open the Actions panel and enter the following code into the
panel:
function eVarValChg (id,
val) {
if (id == "doorstatus" && val == "closed") {
forwardarrow._visible = false;
door._visible
= true;
}
else if (id == "doorstatus" && val == "open") {
forwardarrow._visible
= true;
door._visible =
false;
}
}
var doorVal =
_parent._parent.getEnvironVar("doorstatus");
if (doorVal == "true") {
door._visible = true;
forwardarrow._visible
= false;
} else {
door._visible = false;
forwardarrow._visible
= true;
}
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 doorstatus, which will be the name of our
environment variable. If it is, then the routine sets the visibility
of the closed door button to visible (true) or invisible (false),
depending on whether the value coming in is closed or open. The next line, forwardarrow._visible = false;, sets the visual display of the forward arrow to be false, or invisible, when the door is shown.
The second block is an instruction to execute
when the movie first loads. Instead of waiting to be told the value of doorstatus, it queries
CommandSim for the value, and based on the value, it sets the door closed Button 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 doorstatus 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, doorstatus)
which cannot have spaces, and the starting value. Type in a name, type
in doorstatus for the
id, and make the starting value closed if you want the door to be closed by default, or open if you want to start the scenario with the door already open.
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 (closed or open), 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 <environVars/>
<environVars>
<environVar value="closed" id="doorstatus" name="door status"/>
</environVars>
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.
Now the door will be closed by default. If the instructor changes the environment variable (in the panel) to open, the door will open. The last step is to allow participants to open or close the door by themselves.
Back in Flash, with your file open, we are now going to hook up the button action (the clicking). Select the closed door and then click on the menu Window > Actions. Copy the following code to that panel:
on (press) {
door._visible = false;
forwardarrow._visible
= true;
_parent._parent.setEnvironVar("doorstatus", "open");
}
This tells Flash that when the participant presses the closed door, it will make the closed door instance invisible, and also tell the arrow to show itself (make itself visible). Finally, it tells CommandSim to set the status of the doorstatus environment variable to open, which will get communicated to the other participants in case they are standing alongside the participant who opened the door.
Other Extensions
You can use the same idea to make a way to close the door, if you'd like -- just make a button for the open door in addition to the closed door button. Also, if you want to show smoke when a door is opened, you use this same process for the open and closed door, but you make your smoke show or hide depending on the status of the door environment variable. That is a more advanced topic.