Icon

Cross-Platform Projector Publishing in Director MX 2004, Part 1

A little primer before we get too fancy

After my recent "must buy" review of Director MX 2004, suffice it to say that I think DMX04 is once again the mack daddy (or is it the daddy mack? Or am I so hopelessly stuck here in my 1992 Kriss Kross getup that it doesn't even matter?). Regardless of my current street cred, one of the mack-daddiest features packed into DMX04 is the ability to publish Mac or Windows projectors from a single copy of Director on either platform. However, the seas can get a little rough once you actually try to make things cross-platform, and they can get even rougher when (heaven forbid) you start throwing Xtras into the mix, so here are a few pointers on keeping the waters calm.

For some of you, what follows may be entirely moot. After all, if you're planning nothing more than an entirely self-contained Director movie, you won't need to worry about any specific cross-platform issues since all of that will be handled transparently at publish time. But for those of you that may be embarking on a project that requires some measure of platform sniffing and/or OS-specific code, fate has smiled upon you this day, my friend. I'm going to walk through a real-world example that does exactly that. Specifically, I'm going to create a cross-platform Director projector that uses the outstanding BuddyAPI Xtra to launch a PDF file from the CD it's going to be running from. While all the subsequent code has been grabbed from an actual project I did, I've stripped it down to its base elements in order to keep things discrete, so you'll have to pardon the amazing lack of flair in the project examples. With that out of the way, let's get down to business.

Step 1: Know your Xtras

Sadly, not every Xtra in the world is cross-platform, so if you're planning on using an Xtra in your project, there's a bit of homework to be done before you can really get down to some quality coding. Xtras seem to fall into one of four categories these days:

  1. Fully cross-platform
  2. Mostly cross-platform
  3. Single platform, but with a dummy Xtra for the other platform
  4. Single platform with no dummy Xtra

Obviously, it would help to know what kind of Xtra you have on hand before you start so you can figure out the best way to deal with it, but first thing's first: just what in the name of tarnation is this "dummy Xtra" nonsense I've been spewing? Glad I asked. A dummy Xtra is a companion for the "real" Xtra, usually created for the non-target platform so Director won't pitch a hissy fit trying to execute code it knows nothing about. These dummy Xtras are useful not only on the end user side of things, but their existence also means that you can (in theory) author a Windows Director movie with a Windows-only Xtra entirely on the Mac, for example (or, of course, the other way around). WebXtra from Tabuleiro is one such example. It embeds an instance of Internet Explorer right into the Director environment, yet only does so for Windows Projectors. However, Tabuleiro provides a dummy Xtra that is helpful for both Mac users (again, so "alien" code doesn't render an error) and developers (who can conceivably author a project that utilizes WebXtra on the Mac).

Since I'm using BuddyAPI for this example, I already know that it falls into the "mostly cross-platform" camp. That means there are native BuddyAPI Xtras for Mac and Windows, though not every feature from the Windows version is accessible on the Mac. Fortunately, the developer does provide one of those aforementioned dummy Xtras for the missing Windows features as well. However, I know going in (from reading the manual and all that other good research-y type stuff) that the one thing I'm going to call on BuddyAPI to do (launch a PDF file) is supported on both platforms, so I don't need to worry about anything other than providing the core BuddyAPI Xtras for my Projector to use.

Regardless of the category your chosen Xtra falls into, it's probably a bad idea to leave things to chance. What this means for me is that I usually prefer to take matters into my own hands, so to speak, through platform-specific Lingo code, which in practice ultimately means that I'm going to need to "inform" Director of certain cross-platform things so my Projector is fully aware of what's going on before any Xtra is ever called. This leads us rather seamlessly into step 2.

Step 2: Identify your specific cross-platform code

Today, I'm going to be telling BuddyAPI to open up a PDF, so I'll need to know where that PDF will "live" so I can pass that information along to the Xtra. Problem is, Macs and Windows deal with file paths differently, so I'm going to need to take that into account. On the Mac, (even Mac OS X, as far as Director is concerned), file paths look like this:

Macintosh HD:Path:To:YourFile.pdf

On Windows, the same path would look like this:

C:\Path\To\YourFile.pdf

It's not hard to see that this could present a problem in a cross-platform projector. But it's an easy fix. First, I already know that Director's _movie.path Lingo is going to remove the whole knowing if I'm dealing with Macintosh HD or C:\ issue here, as Director can automagically trace the path to where the running projector is sitting. The only thing left is to detect what platform I'm on, and then set a variable that represents either the colon (Mac) or backslash (Windows) delimiter so I can use common data to build paths dynamically. Here's the Lingo code to place in a moviescript to do just that:

on startMovie
 global gPlatform, gDelimiter
 if the platform contains "Windows" then
  gPlatform="win"
  gDelimiter="\"
 else if the platform contains "Macintosh" then
  gPlatform="mac"
  gDelimiter=":"
 else
  gPlatform="none"
  gDelimiter="none"
 end if
end

In case that was Greek (or Lingo, as the case may be) to you, here's what I did in English:

when the movie starts,
 I'm going to be naming two global variables gPlatform and gDelimiter so I can use them later
 now, if you're running on Windows,
  make the global variable "gPlatform" have a value called "win" and
  make the global variable "gDelimiter" a backslash
 or, if you're running on a Mac,
  make the global variable "gPlatform" have a value called "mac" and
  make the global variable called "gDelimiter" a colon
 or, just in case you're running on neither (which is impossible but I'm anal retentive),
  make the global variable "gPlatform" have a value called "none" and
  make the global variable called "gDelimiter" have a value called "none" too
 got it?
see ya

Make sense? Good. Basically, I'm doing my platform sniffing right when the movie opens and then stashing two variables I can use in any number of ways later. Now, in this mini-example, setting the delimiter is the only snippet of platform-specific code I'm going to have to account for, but obviously things can get more complex with projects that do more stuff. But I've hooked myself up, in a manner of speaking, just by declaring the gPlatform variable, so even if things get chaotic I should still be in good shape to write some more complex code if the need arises. Anyway, the only other thing I'll have to do is create a button and use the variables I declared to create the proper path relative to my Projector, and then launch the file. Now, I already know that I have a folder called "contentfolder" inside the same directory as my Director movie, and in that folder I have a PDF file called "helloworld.pdf" (fig. 1). So, I'll create a new script with the following code, which I'll then drag on top of a super-simple button I've already created (fig. 2):


Figure 1: Told you I have a PDF file in my contentfolder directory. You should have believed me.

on mouseUp me
 global gDelimiter
 myFolderName="contentfolder"
 myPDFName="helloworld.pdf"
 myTempPath=_movie.path&myFolderName&gDelimiter&myPDFName
 baOpenFile(myTempPath, "normal")
end


Figure 2: Please, try to contain your excitement at seeing such visually stunning design here. We've got work to do, after all.

Again, in (sorta) plain English:

once the user is done clicking the mouse,
 I'm going to use that gDelimiter variable I told you about before
 here's a new variable, myFolderName, which I'll give a value of "contentfolder"
 here's another new variable, myPDFName, which I'll give a value of "helloworld.pdf"
 here's yet another new variable, myTempPath, which strings the path to the Projector together with the delimiter I told you about earlier with the specific path info to my PDF file
 take that myTempPath variable and call out to BuddyAPI to open the file
that's it

Hopefully, this is all still making sense. I realize that what just transpired might be a bit of a diversion from where we're collectively trying to go, but it's probably helpful to have included some general cross-platform hints while we're roaming around the general neighborhood. Anyway, at this point, I'm completely done coding my movie and am ready to publish, but I'm not quite finished yet. There are some ducks to get into a row before I know everything will work correctly on both platforms, but we'll leave that for next time. Until then, folks!

^ Top of Page

Got Feedback? to send an email. I'll do my best to answer. Really.