1. --!movie
  2. --!encoding=utf-8
  3.  
  4. ----------------------------------------
  5. -- Exports vectorShape member as SWF file
  6. -- Usage:
  7. -- ok = exportSWF( member("MyVectorShape"), _movie.path&"export.swf" )
  8. --
  9. -- @param {member} aVectorMember
  10. -- @param {string} aSwfFile
  11. -- @return {bool} success
  12. --
  13. -- @requires clipboard xtra
  14. -- @requires fileIO xtra
  15. ----------------------------------------
  16. on exportSWF (aVectorMember, aSwfFile)
  17.   if aVectorMember.type<>#vectorShape then return FALSE
  18.  
  19.   -- copy vectorShape member to clipboard
  20.   aVectorMember.copyToClipBoard()
  21.  
  22.   -- get Director's custom data for members in clipboard (as byteArray)
  23.   cx = xtra("clipboard").new()
  24.   if the platform contains "win" then
  25.     ba = cx.clipGetData("DIRECTOR:1005")
  26.   else
  27.     ba = cx.clipGetData(1005)
  28.   end if
  29.   if voidP(ba) then return FALSE
  30.  
  31.   -- find offset of "FWS" (=start of SWF data) in byteArray
  32.   swfStart = bytesOffset("FWS", ba)
  33.   if swfStart=0 then return FALSE
  34.  
  35.   -- get length of SWF data
  36.   ba.position = swfStart+4
  37.   swfLen = ba.readInt32()
  38.  
  39.   -- extract the SWF data, and save it to file
  40.   ba.position = swfStart
  41.   ba = ba.readByteArray(swfLen)
  42.   return putBytes(aSwfFile, ba)
  43. end
  44.  
  45. ----------------------------------------
  46. -- Finds position of string (or byte list) in byteArray
  47. -- Note: case-sensitive!
  48. --
  49. -- @param {string|list} aNeedle
  50. -- @param {byteArray} aHaystack
  51. -- @return {integer} position
  52. ----------------------------------------
  53. on bytesOffset (aNeedle, aHaystack)
  54.   if stringP(aNeedle) then
  55.     s = aNeedle
  56.     aNeedle = []
  57.     len = s.length
  58.     repeat with i = 1 to len
  59.       aNeedle[i] = chartonum(s.char[i])
  60.     end repeat
  61.   end if
  62.   cnt = aHaystack.length - aNeedle.count + 1
  63.   cnt2 = aNeedle.count
  64.   repeat with i = 1 to cnt
  65.     ok = TRUE
  66.     repeat with j = 1 to cnt2
  67.       if aHaystack[i+j-1]<>aNeedle[j] then
  68.         ok = FALSE
  69.         exit repeat
  70.       end if
  71.     end repeat
  72.     if ok then return i
  73.   end repeat
  74.   return 0
  75. end
  76.  
  77. ----------------------------------------
  78. -- Saves byteArray to file
  79. --
  80. -- @param {string} aFile
  81. -- @param {byteArray} aByteArray
  82. -- @return {bool} success
  83. --
  84. -- @requires fileIO xtra
  85. ----------------------------------------
  86. on putBytes (aFile, aByteArray)
  87.   fp = xtra("fileIO").new()
  88.   fp.openFile(aFile, 2)
  89.   err = fp.status()
  90.   if not (err) then fp.delete()
  91.   else if (err and not (err = -37)) then return FALSE
  92.   fp.createFile(aFile)
  93.   err = fp.status()
  94.   if (err) then return FALSE
  95.   fp.openFile(aFile, 2)
  96.   err = fp.status()
  97.   if (err) then return FALSE
  98.   fp.writeByteArray(aByteArray)
  99.   fp.closeFile()
  100.   return TRUE
  101. end
  102.  
[raw code]