Distributed Information

The first thing to understand about the Internet is that, while there are protocols and conventions in use with which you may be unfamiliar, there’s little real difference in the way files are stored on Net machines compared to how they’re stored on your own desktop system. The data is still all ones and zeros. The only major differences are these:

Discussion of Internet communication protocols and security (in any depth) is considerably beyond the scope of this text. However, fortunately, you don’t really need to know that much about such topics to be able to get basic Internet operations in place in your Director movies.

In this module, we are most interested in the operations that can handle Web page content and that can retrieve remote files, such as other Director-readable media that may be online someplace.

Web Content

You already explored some of the possibilities in retrieving HTML pages with getNetText in a #text member. Well, it might not surprise you much to know that your Director movies can be made to react to hyperlinks in #text members as well.

Note: A hyperlink is represented in an HTML page, usually, by text that is blue in color and underlined. It’s the part of the HTML page you click to get someplace else in your browser. Now we’re returning to the idea of an online information pool, and I’m going to show you how you can intelligently handle hyperlinks in your Director movies (provided the HTML page you’re using in the movie has been designed with a few limitations in mind).

Start, as always, with a new Director movie and place a #text member on the Stage. Give it the following behavior:
 

PROPERTY pnWebRetrieve, psServerPrefix
 
 
 

on beginSprite me
 
 

clearCache
pnWebRetrieve = 0
psServerPrefix = "http://www.nightwares.com/director_beginners_guide/11/"
sTarget = "index.htm"
pnWebRetrieve = getNetText ( psServerPrefix & sTarget )

END beginSprite me
 
 
 

on exitFrame me
 
 

if pnWebRetrieve <> 0 then
 
cursor 4

if netDone( pnWebRetrieve ) then
 

sprite(me.spriteNum).member.html = netTextResult ( pnWebRetrieve )
sprite(me.spriteNum).member.media = sprite(me.spriteNum).member.media
pnWebRetrieve = 0
cursor -1


end if


end if

END exitFrame


Some of this you’ve seen before, way back in Part 1. Some of this will be new to you.

clearCache

This clears Director’s cache of previously downloaded pages. I’ve added it here because almost everyone runs into trouble when doing a getNetText operation that happens to include pages that have changeable content.

What happens is that Director stores a cache of Web pages it’s previously downloaded, so if you try to do a getNetText operation on a page you’ve already seen, it’ll pull that page from its cache. This is to save time, because loading a page from the local cache is quicker than going out to the Net and retrieving it all over again.

However, if you’re editing your HTML content live in something like Dreamweaver or Netscape Composer and comparing it to the visual and programming results in a Director movie, you will not see the changes you’ve made reflected in your getNetText operations, because the old page will still be in Director’s cache, and that will be what gets displayed after the getNetText call.

Thus, to get around that problem, we issue a clearCache command that takes place every time you click the Play button, ensuring that the page being displayed is, in fact, the most current version.

Every Director programmer­and I mean every one­runs into hitches with getNetText and the download cache, forgetting to do a clearCache at the right place and mistakenly getting the wrong data. Some programmers work on the problem for hours, believing perhaps it’s a problem with their server or Internet connection. I might have just saved you half a day’s future frustration.

pnWebRetrieve = 0

This will be our Internet operation ID.

psServerPrefix = "http://www.nightwares.com/director_beginners_guide/11/"

This is the server address to a location I have online containing the content we’re going to retrieve. We hard-set the prefix for reasons that will become apparent shortly.

sTarget = "index.htm"

This is an initial page target.

pnWebRetrieve = getNetText ( psServerPrefix & sTarget )

This initiates a getNetText operation, telling Director to begin loading the specific page named in sTarget from the location we gave it earlier in psServerPrefix.

We then go on to the frame event script:

if pnWebRetrieve <> 0 then

cursor 4

If there’s some kind of Web retrieve operation going on, we turn the cursor into an hourglass (Windows) or watch (Mac) to let the user know that something is happening:

if netDone( pnWebRetrieve ) then

sprite(me.spriteNum).member.html = netTextResult ( pnWebRetrieve )

sprite(me.spriteNum).member.media = sprite(me.spriteNum).member.media

pnWebRetrieve = 0

cursor -1

end if

If the Net operation is finished, we plug the HTML we just got into our #text member and reset the cursor to the system default (usually an arrow). We also set the Net retrieve ID to 0 so Director doesn’t continue thinking we’re trying to download anything. (After all, we got it already.)

I want you to notice this line especially:

sprite(me.spriteNum).member.media = sprite(me.spriteNum).member.media

This is a workaround to a bug in Director that’s been present since version 7. If you dynamically alter the HTML of a #text member, its hyperlinks will not function unless you set the media of the member equal to itself. Though I can’t tell you for certain why this happens, I suspect it has to do with needing to "remind" Director of what a given #text member’s contents are, especially if there are interactive elements (such as clickable hyperlinks) involved. Think of it as the Cast member equivalent of an updateStage call.

If you click the Play button now (and you’re online), in a few moments, the index.htm page I prepared for this module should appear in your #text sprite. If you’re not online, your computer should do a dial-up connection, after which you’ll see the index.htm page.