Articles Archive
Articles Search
Director Wiki
 

Shockwave Communication

November 27, 1997
by Pat McClellan

Dear Multimedia Handyman
Is there a way for Shockwave movies to talk to each other -- like MIAWs can talk to the stage? I want to have a light switch in one movie & the corresponding bulb in another movie.

Signed,

Remote Switcher

Dear Switcher,

Since MIAWs are disabled in Shockwave, you've got to use a different strategy. The new version of Shockwave uses just one instance of the plugin to run all of the movies on the page, so you'd think that those movies should be able to communicate. Unfortunately, they can't. There has been a lot of discussion about this capability on the listservs, so I know Macromedia is at least considering this functionality for future versions.

In the meantime, there's a simple (but indirect) way of passing information between movies. You let one movie create a prefs file (stored automatically in the plugin folder) and then the other movie can retrieve that info from the file. The commands you want are "setPref" and "getPref". I think the example of setPref in the Lingo dictionary is confusing, but otherwise, it's easy to use.

You need <a href="http://www.macromedia.com/shockwave/">ShockWave</a> 6 to view this movie!
You need <a href="http://www.macromedia.com/shockwave/">ShockWave</a> 6 to view this movie! You need <a href="http://www.macromedia.com/shockwave/">ShockWave</a> 6 to view this movie!

For your example -- a switch & a light -- here's how to do it. In the switch movie, create the setPref file and write either a "0" or a "1" to it. We'll say "O" is for off and "1" is for on. Note that the prefs file is a TEXT file, so you have to write the data as a string. Also, for cross-platform compatibility, make sure the name you specify for the prefs file is 8 standard characters or less.

Now, attach a script to your switch sprite so that it toggles between on and off, and use the setPref command to update the prefs file each time the switch is changed.

  on mouseUp me
        global gSwitchToggle
        if gSwitchToggle = 0 then
                set gSwitchToggle = 1
        else
                set gSwitchToggle = 0
        end if
        setPref ("switch",string(gSwitchToggle))
  end 

Next, in your bulb movie, you need to set up a monitoring device. This is simply a handler which will periodically read the prefs file and then act on the information. Here's what I used:

  on idle
        set status = getPref ("switch")
        if NOT voidP(status) then
                if status = "1" then
                        go to frame "light on"
                else
                        go to frame "light off"
                end if
        end if
  end

That's all there is to it. Although this solution is less elegant than direct communcations between movies, this approach is easy and work pretty well. There is a bit of a time lag as the prefs file is written... then read, but for most applications, you'll be satisfied with the results.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.