Articles Archive
Articles Search
Director Wiki
 

text to URLs

March 9, 1998
by Pat McClellan

Dear Multimedia Handyman,

I would like to know if it is possible to have an external text file that is a series of site names and URLs. I then want the Shockwave movie to call that file and read it in as links - which are displayed as formatted links in the dcr that can be clicked on to surf. The called links would be displayed in text that is preformatted via lingo, and whenever I update the text file/cast, the MNI would simply read those new ones in with the proper preformatted text displayed.

Example -- text file would have something like this in it:

CNN Interactive, http://www.cnn.com
NewsPage, http://www.newspage.com
ESPN Online, http://www.espn.com

and the Shockwave movie would display only this:

CNN Interactive
NewsPage
ESPN Online

And if I want to update - I just edit the external text file/cast and add or subtract the links.

Steven (Alex) Alexander


Dear Alex,

Good question because it involves two valuable techniques. The first is retrieving info from an external text file (on the net). Then, we'll process the incoming text file -- displaying the first part of the line & stashing the second part as a URL property. We'll start with the getNetText behavior in the Behavior Library that comes with Director. I won't regurgitate the code here, but I recommend that you open up that behavior & follow along.

This behavior gets the text and plugs it into a field (designated by Target Sprite). So, we'll leave the first part intact, but alter the behavior so that instead of plugging the text into the field, it calls a handler in the field sprite's behavior which processes the text. Don't worry, it sounds complicated but we'll do it step-by-step. NOTE: we only want to alter a copy of the behavior, NOT the one in the library. So copy the behavior into your internal cast and work on that one.

In the getNetText behavior, find the on finishOperation handler. Now look through it until you find the following lines:

set outputMember = the member of sprite pResult
set the text of outputMember = netTextResult(pNetID)
This is the part which takes the returned text which is currently held in the variable called netTextResult(pNetID) and plugs it into the field which is in the sprite channel designated by the value of pResult. Let's comment out those 2 lines, like this...
-- set outputMember = the member of sprite pResult  
-- set the text of outputMember = netTextResult(pNetID)
Now, we'll add our own lines. The first line is simply for clarity. The second line sends a message to sprite pResult to process the text.
      set theFullText = netTextResult(pNetID)
        sendSprite(pResult, #processURLs, theFullText)
That takes care of sending the message to the field sprite behavior and sends along the full text to be processed. Let's write the URL processing behavior now. You'll drop this on the field in which the links will be displayed.

We'll be using some lingo terms which apply to text handling. Quick review: line 1 of any text block equals everything up to the first line return; item 1 of any line equals everything up to but not including the itemDelimiter (we'll set the itemDelimiter to ","). So, in our text document, item 1 of each line is the part we want to display, and item 2 is the URL of the link. (Note that in my text file, I did NOT include a space after the comma. If you include the space, item 2 will begin with a space and it won't work right.) We'll need to build a list of those URLs and store the list in a property called pURLlist.

-- Process text into URL links 
property pURLlist -- list of URL links
on processURLs me, theFullText
  set pURLlist = [] -- initialize list
  set mySprite = the spriteNum of me
  set myMember = the member of sprite mySprite
  set myFieldName = the name of myMember
  set howManyLines = the number of lines in theFullText
  set the itemDelimiter = ","
  repeat with i = 1 to howManyLines
    if line i of theFullText > "" then
      set linkName = item 1 of line i of theFullText
      put linkName into line i of field myFieldName
      add (pURLlist, item 2 of line i of theFullText)
    end if
  end repeat
  set the fontStyle of field myFieldName = "underline"
end
on mouseUp me
  set whichLink = the mouseLine
  set theURL = getAt (pURLlist, whichLink)
  goToNetPage theURL, "_new"
end
After theFullText is processed, the site names are displayed and the links are stored in the pURLlist. The mouseUp handler actually makes the link between what is clicked and the site that is called with the goToNetPage command.

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

You can play with this behavior to add stylistic features. Some suggestions: change the forecolor of the link on mouseDown and after it has been clicked; allow the author to specify a target frame. Have fun experimenting and good luck with your project.

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.