l i v e c o d e

Loading Externals the Easy Way
Mac OS 9 Mac OS X Windows Linux

A number of people have had difficulties in getting externals to load, and so this tip is designed to help people with this process.

The basic idea is that a separate stack is used to hold the connections to the external(s) you wish to load, and then putting it into use as a library stack with the start using command makes the externals available to the rest of your stacks.

The tip below assumes you have already set the defaultFolder to the location of where your externals reside on disk. It will create a stack in memory to hold the externals and load it as a library automatically. Since it is only in memory, it will disappear when your applications has quit.

on loadAppExternals
  local tExternals

  ----------
  --> EXTERNALS
  ----------
  put "myExternal.bundle" &cr& "myExternal.dll" into tExternals

  ----------
  --> CREATE EXTERNALS STACK IN MEMORY
  ----------
  if tExternals <> empty then
    if there is not a stack "myExternals" then
      reset templateStack
      set destroyWindow of templateStack to true
      set destroyStack of templateStack to true
      set visible of templateStack to false
      set externals of templateStack to tExternals
      create stack "myExternals"
      reset templateStack

      get defaultStack
      go stack "myExternals"
      start using stack "myExternals"
      set defaultStack to it
    end if
  end if
end loadAppExternals

The above code is fine if you already know the names of the externals have already set the defaultFolder to where the externals are. Here's a variation of the loadAppExternals handler that allows you to pass in a path to the folder that contains the externals and it will do the rest:

on loadAppExternals pExternalsFolderPath
  local tExternals,tCurrDir

  ----------
  --> EXTERNALS
  ----------
  if there is a folder pExternalsFolderPath then
    put the defaultFolder into tCurrDir
    set the defaultFolder to pExternalsFolderPath
    switch (the platform)
      case "MacOS"
        put the folders into tExternals
        break
      case "Win32"
        put the files into tExternals
        break
    end switch
    set the defaultFolder to tCurrDir
    filter tExternals without ".*"   -- remove any invisible files/folders
  end if
  ----------
  --> CREATE EXTERNALS STACK IN MEMORY
  ----------
  if tExternals <> empty then
    if there is not a stack "myExternals" then
      reset templateStack
      set destroyWindow of templateStack to true
      set destroyStack of templateStack to true
      set visible of templateStack to false
      set externals of templateStack to tExternals
      create stack "myExternals"
      reset templateStack

      get defaultStack
      go stack "myExternals"
      start using stack "myExternals"
      set defaultStack to it
    end if
  end if
end loadAppExternals
Top example posted 8/11/2005 by Trevor Devore to the Use Revolution List
Bottom example modifications by Ken Ray as of 10/16/2006

 Print this tip

News and Rumors Products Services Developer Resources Contact STS About STS