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

HowTo: Checking for the presence of an Xtra

 

 

 

Home
Workshop-Seite

Deutsche Version

view demo movie

Sometimes it may be necessary to check whether an Xtra exists or not, e.g. in Shockwave applications, or if you are doing authoring-tools or ready-to-use code snippets and behaviors, or if you have code that may be executed by several different Xtras and you want to use the one that is present on the user's machine.

My JPEG export behavior - downloadable here - does such an Xtra check; the MacOS gestalt example (here), that is easily adaptable to at least 4 different Xtras, does checks to determine which Xtra to use.

These are some ways to check for an Xtra's availabilty:

  1. the xtraList (all Xtras, but slow)
  2. Checking for Lingo Xtras
  3. Checking for Asset Xtras
  4. symbol table
  5. Some short-circuit checks

Joachim Gola




 

 

 

 

The xtraList

The normal way to check for Xtras in Director 7 is to examine the xtraList. The following script returns TRUE if all Xtras passed as params are present in the XtraList. You have to pass in a list of Xtra (file) names such as mytest = checkXtras (["JavaConvert", "Mix Services", "JPEG Export", "Image Translator Helper"]).

on checkXtras theXtras
  temp = the xtraList
  repeat with i = 1 to temp.count()
    -- check every xtra's presence
    mytest = thextras.getpos(temp[i].name)
    -- if present, delete the Xtra's name from theXtras
    if mytest > 0 then theXtras.deleteat(mytest)
  end repeat
  if theXtras = [] then return TRUE
  else

    -- prepare alert message
    retval = ""
    repeat with i = 1 to theXtras.count()
      retval = retval & theXtras[i] & " "
    end repeat
    alert "Xtra(s) missing"&return&retval
    return FALSE
  end if
end

If you only want to check one Xtra, and don't need an alert, it's a lot shorter:

on checkXtra theXtra
  temp = the xtraList
  repeat with i = 1 to temp.count()
    if temp[i].name = theXtra then return true
  end repeat
  return false
end

If you do that in authoring, both tests will take quite a while, since the numbers of xtras Director has to look for when the it builds the xtralist is rather big.

So we have to look for alternates... more.




 

 

 

 

Checking for Lingo Xtras

There is the well-known way to check for Lingo-Xtras only with the number of xtras. Here, you have to pass in a list of (internal) Xtra names - the ones you get when you do a showXlib in the message window:

on checkLingoXtras theXtras
  temp = the number of xtras
  repeat with i = 1 to temp
    mytest = thextras.getpos((xtra i).name)
    -- if present, delete the Xtra's name from theXtras
    if mytest > 0 then theXtras.deleteat(mytest)
  end repeat
  if theXtras = [] then return TRUE
  else
return FALSE
end

Or, if you only want to check for one Lingo Xtra's presence:

on checkLingoXtra oneXtraName
  temp = the number of Xtras
  repeat with i = 1 to temp
    if (xtra i).name = oneXtraName then return true
  end repeat
  return false
end

put checkLingoXtra ("UiHelper")
-- 1




 

 

 

 

Checking for Asset Xtras

If you want to check for an Asset Xtra's presence, there is a method that Bruce Epstein suggests in Lingo in a Nutshell: try to create a member of the wanted type; if it fails, the necessary Xtra is not present (LIAN page 524). You'll pass-in a member type such as #flash or #alpha:

on checkAssetXtra oneAssetType
  testmember = new(oneAssetType)
  if ilk(testmember) = #member then
    erase testmember
    return true
  else
    return false
  end if

end

put checkAssetXtra (#flash)
-- 1




 

 

 

 

Using the symbol table

The last and undocumented way to check for most Xtras' presence is also due to Bruce Epstein. In LIAN page 521-525, he describes the Director symbol table in a great way, and he gives us a way to determine whether a symbol (e.g. command name, member type, variable name, Lingo symbol, user defined symbol, user defined handler names...) is in this global symbol inventory:

on existingSymbol symbolName
  global gInitialSymbolCount
  -- Record the last symbol defined when first called
  if voidP(gInitialSymbolCount) then
    newsymbol = symbol("uniqueSymbol" & the ticks)
    gInitialSymbolCount = (newSymbol + 0)

  end if
  -- Compare the number of the symbol to test to gInitialSymbolCount

  checkSymbol = (symbol(symbolName) + 0)
  if checkSymbol < gInitialSymbolCount then return TRUE
  else return FALSE
end

We first create a new unique symbol to get the actual number of symbols present in the symbol table.
If the param symbolName
that is passed-in (as string) is a predefined Director symbol, we'll get a symbol number less than gInitialSymbolCount; if it has not been present in the symbol table before, we'll create it and its number will be greater than gInitialSymbolCount.

There are good reasons NOT to use this code for a serious Xtra check. If a symbol is used before the test is executed (e.g. because you named a global with the same name, or you used the Xtra in a previous session), the symbol exists and the test will always return true - even if the Xtra to test does not exist. The demo movie contains this option - use it for fun, NOT for a Xtra check.

Baring that in mind, it works if you pass in either an Xtra's handler name (for Lingo Xtras) or an asset type (for AssetXtras). Both have to be strings!

put existingSymbol ("flash")
-- 1
put existingSymbol ("vectorshape")
-- 1
put existingSymbol ("closed") -- a #vectorshape property
-- 0      -- use member type instead!
put existingSymbol ("ExportMedia") -- a JavaConvert Xtra function
-- 1

There is no way though to check for Agent Xtras and MIX Xtras like "Mix Services", "JPEG Export", "Image Translator Helper" with this method.




 

 

 

 

Some Xtras allow for special short-circuit checks (Win-only):

if (the soundDeviceList).getpos("QT3Mix") > 0
   -- QuickTime 3 Asset Xtra is present AND QuickTime >= 3 is present

if (the soundDeviceList).getpos("DirectSound") = 1
   -- DirectSoundXtra is present AND DirectSound version is >= 5





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