D7WS HOMEPAGE WORKSHOP NEUE XTRAS GALERIE WORKSHOP Automatic Translation LESERSERVICE BUCH NEWS

HowTo: Shockwave-Browser-Shockwave - Communication

 

 

 

Home
Workshop-Seite

Deutsche Version
(baldmöglichst!)

open testpage

It should be easy, but it is tricky – LiveConnect- and ActiveX-Scripting is still a field where nothing works as it should work. I did a test movie / test page and I want your help: does it work on your browser / Shockwave- setup? Mail the results! (joachim@viergleicheins.de)

You should be able to do the following with the test setup:

  • Call a JavaScript function and get its return value into Shockwave.
  • Use simple JavaScript functions to manipulate the movie's playing state, position and to call another movie.
  • It should work with Netscape > 3 (Java enabled) AND MSIE > 3 (ActiveX-Control). It won't work on Win31, MacOS 68K, non-java-enabled Netscape browsers, or on MacOS MSIE (any version). Test it with the Shockwave 7 plug-in, since the movies are made with Director 7.

The original scripting is from John Dowdell at Macromedia and was done for Shockwave 6. Since I got strange error reports, there may be additional problems with Shockwave 7, especially on Windows / Netscape.

The Director lingo scripting is quite simple; the important parts can be found in the HTML page. Have a look at the comments down this page.

BTW: EVERYTHING works great for me on MacOS / Netscape 4.07 and on Windows / MSIE 5. Some problems reported with Netscape Windows. Tell me if it's OK for you on Netscape Win!

the scripts -- the browser stats




 

 

 

 

Director scripting:

The button scripts (using externalEvent to send command to Javascript / VBScript):

on mouseUp me
  externalEvent("GetJSValue()")
end

The receive handler (called from JavaScript and evaluated in the Shockwave movie):

on evalScript args
  set commandName to item 1 of args
  set theValue to item 2 of args
  case value(commandName) of
    #incoming: set the text of field "display" to theValue
  otherwise: alert string(commandName)
  end case
end




 

 

 

 

The HTML- / JavaScript-Code:

<html> <head>

The JavaScripts are defined in the <HEAD> section. GetJSValue() will return the content of the below form input field to Shockwave.
Since there MUST be a short delay if messages are exchanged via LiveConnect, the Shockwave movie will first call the JavaScript function, then the function will be called by itself with a time-out of 300 milliseconds. Strange technique, but apparently liveConnect needs the short delay to have some time to breathe.
TestFunction will only alert; no value is passed back to Shockwave.

<script language="javascript">
function GetJSValue(selfcall) {
if (selfcall == null) {
  setTimeout("GetJSValue(1)", 300);
} else {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    movieID = myMovie;
  } else {
    movieID = document.myMovie;
  }
  movieID.EvalScript("#incoming, " + document.forms[0].theField.value);
  }
}
function TestFunction() {
alert("JS test function called");
}
</script>




 

 

 

 

Since MSIE does not allow JScript functions to receive calls from ActiveX elements, we have to setup a VBScript function that passes the function call to JavaScript.
Again a strange technique, but necessary due to the limitations of the JScript implementation in MSIE.

<script language="vbscript">
sub myMovie_ExternalEvent(byVal aCommand)
  if aCommand = "GetJSValue()" then
    call GetJSValue()
  elseIf aCommand = "TestFunction()" then
    call TestFunction()
  end if
end sub
</script></head>

These are the normal <object> and <embed> TAGs with some additional stuff:
- they both have a 'name' attribute for easy adressing from JavaScript.
- they both have a 'autostart' attribute (since I'm not sure whether some problems on Windows/Netscape may be related to having missed this attribute in earlier versions).
- the <embed>-TAG has a
swLiveConnect=TRUE attribution – again since I'm not sure whether it's necessary for Netscape/Windows.

<br>
<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.
macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,0,0"
width="512" height="100" name="myMovie">
<param name="src" value="extevent.dcr">
<param name="autostart" value="true" >

<embed src="extevent.dcr" swLiveConnect="TRUE"
pluginspage="http://www.macromedia.com/shockwave/download/"
width="512" height="100" name="myMovie" AUTOSTART="true">

</embed></object>




 

 

 

 

The FORM allows for the input of text and has a button to send the input to Shockwave (using the above JavaScript function). The second button calls TestFunction() locally – Shockwave is not involved.

<h3> Type here; see if we can get it in Shockwave</h3>
<form>
<p><input type="text" name="theField" value="init"></p><br>
<p><input type="button" value="sendFORMinput" onClick="GetJSValue()"> (should send the value to shockwave) ---
<input type="button" value="testFunction" onClick="TestFunction()"> (should alert)</p><br>

These buttons allow for the manipulation of the Shockwave movie via simple JavaScript calls. The "secondmovie.dcr" uses either go to movie or goToNetMovie to return to the first. It may be necessary to fiddle with the rewind and play buttons to make the second movie useable. Don't know why, any enlightenment would be very much appreciated.

<p><input type="button" value="stop" onClick="myMovie.Stop()">
<input type="button" value="play" onClick="myMovie.Play()">
<input type="button" value="rewind" onClick="myMovie.Rewind()">
<input type="button" value="GotoFrame 5" onClick="myMovie.GotoFrame(5)">
<input type="button" value="GotoMovie" onClick="myMovie.GotoMovie('secondmovie.dcr')">
<input type="button" value="Current Frame" onClick="alert(myMovie.GetCurrentFrame())"><br>
Should do some stuff with the shockwave movie.

</p>
</form>
</body>
</html>

 

Note:

Netscape 4.x uses LiveConnect to allow scripts and plug-ins to communicate, but it deferres the loading of Java – which is necessary for LiveConnect – to the first page that needs Java. If a Shockwave movie does not use LiveConnect, you may set

swLiveConnect=FALSE

in the <EMBED>-Tag to hide Shockwave's LiveConnect abilities.




 

 

 

 

Browser stats: (44 reports) last update: 2000/4/12

Thanks for all the replies and the detailed information provided by you all. I think these are the preliminary conclusions we should take into account when doing browser / shockwave scripting:

(all works as expected)
? (all works as expected, BUT only the first time: "The movie seemed to work the first time that I tried it, but then didn't the second time. Calls to the shockwave are fine, but calls from the shocked piece aren't working." Jennifer Stockton)
* (all works as expected, but there was a long delay when clicking getFORMinput - from "somehow slow" to "thought it was crashed")
(shockwave getFORMinput does not work, probably other things do)

Every *• marks one report.

MSIE Mac: won't work, as stated above
MSIE 5 Mac: won't work, either

MSIE 3 Win: (win95) reports:
MSIE 4, 4.01 Win: (win95) reports: •• -- (win98) reports: •• -- (nt4, ie4.72) reports:
MSIE 5 Win: (win98) reports: *•••• -- (nt4) reports: ••••

Netscape 4.7: (Mac) reports:
Netscape 4.61: (Mac) reports: (Win 98) reports: ••
Netscape 4.6: (Win 98) reports: (Win 95) reports:
Netscape 4.51: (Mac) reports: •••• -- (Win98) reports: -- (win95) reports: ••
Netscape 4.5: (Mac) reports: •••• (Win98) reports: •••?

Netscape 4.01, 4.04, 4.07, 4.08: (Mac) reports: ••• -- (Win98) reports:
Netscape 4.01a: (Mac) reports: *

There is an obvious problem with Netscape Navigator/Communicator 4.51 on Windows. Maybe someone could enlighten that further? Does the "testFunction"-Button in the shockwave movie work with this browser? Does it work on win98 or not?

There is a long delay on the Mac when Java is starting up. Bad, but nothing to worry about.

There is - besides the Java starting thing - sometimes a delay when clicking the shockwave button getFORMinput. No real logic though, also the information about this delay was not very specific (seconds? minutes? hours?;-).

Continue reporting, I'll add the results to this page.

Important

There are some hints that Netscape 4.5 on Windows does not allow external events in the first page that starts LiveConnect. To check against this, try opening the page twice in two windows. If the second window works while the first doesn't PLEASE report it!

joachim gola





Directorworkshop.de ist © Joachim Gola & Gerd Gillmaier 1998-2002. Alle Rechte vorbehalten.