durss

shape2array.jsfl

Jan 21st, 2012
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *
  3. * this script only works under certain conditions:
  4. *       - everything that is selected must be shapes, if not, this doesn’t work (select all and ctrl+b (break))
  5. *       - every shape has to be in a different layer, otherwise the script see it as one shape
  6. *
  7. * The result of this jsfl is not always what you expect…
  8. *       sometimes geometric shapes like squares/rectangles/triangles are all f#$%ed-up (it looks like curves are made to opposite corners)
  9. *       I have no solution for that in this jsfl (in the code), it seems that Flash ‘reads’ the shape wrong (or in the wrong order)…
  10. *       But you could try:  - I used the straighten tool which worked in one case, but not in the other
  11. *                       - rotated a square 90 degrees
  12. *                       - both solutions
  13. *
  14. *
  15. *
  16. * based upon        http://ericlin2.tripod.com/bugwire/bugwiret.html
  17. * and           http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00003869.html
  18. *
  19. *</pre>
  20. <pre>*  ____                   _      ____
  21. * |  __| _ __ ___    ___ | | __ |__  |
  22. * | |   | '_ ` _ \  / __|| |/ /    | |
  23. * | |   | | | | | || (__ |   <     | |
  24. * | |__ |_| |_| |_| \___||_|\_\  __| |
  25. * |____|                        |____|
  26. *
  27. * </pre>
  28. *
  29. *
  30. * @author           Matthijs C. Kamstra [mck]
  31. * @version      1.1
  32. * @since            10:00 5-5-2008
  33. *
  34. * Changelog:
  35. *       v1.1 [2008-05-09] - test movie after use of this jsfl
  36. *       v1.0 [2008-05-05] - Initial release
  37. *
  38. *
  39. */
  40. var currentVersion = '1.1';
  41. fl.trace ('[mck] shape2Array :: version ' + currentVersion);
  42. // with a shape selected
  43. var ptArray = [];
  44. var doneEdge = [];
  45. var exportString = 'var shapeArrayz:Array = new Array ();\n';
  46. var selectionNumber = 0;
  47. // fl.trace("// start ---------------------------");
  48. function isDrawn(id) {
  49.     for (var k = 0; k<doneEdge.length; k++) {
  50.         if (doneEdge[k] == id) {
  51.             return true;
  52.         }
  53.     }
  54.     return false;
  55. }
  56. sel = fl.getDocumentDOM().selection;
  57. for (var n = 0; n < sel.length; n++) {
  58.     exportString += 'shapeArrayz['+n+'] = [';
  59.     selectionNumber = sel.length;
  60.     var elt = sel[n];
  61.     if (elt.elementType != 'shape') {
  62.         continue;
  63.     }
  64.     elt.beginEdit();
  65.     for (i=0; i<elt.contours.length; i++) {
  66.         var cont = elt.contours[i];
  67.         var he = cont.getHalfEdge();
  68.         var startId = he.id;
  69.         var id = 0;
  70.         while (id != startId) {
  71.             var ed = he.getEdge();
  72.             if (!isDrawn(ed.id)) {
  73.                 doneEdge.push(ed.id);
  74.                 for (var j = 0; j<3; j++) {
  75.                     var pt = ed.getControl(j);
  76.                     ptArray.push(pt.x, pt.y , j);
  77.                     exportString += '[' + pt.x + ',' + pt.y + ',' + j + '] , ';
  78.                 }
  79.             }
  80.             he = he.getNext();
  81.             id = he.id;
  82.         }
  83.     }
  84.     elt.endEdit();
  85.     exportString += '];\n';
  86. }
  87. // fl.trace(ptArray);
  88. // fl.trace("// end ---------------------------");
  89. // I'm a lazy bastard, so paste the code in the as layer
  90. // create or place code in 'as' layer
  91. var tl = fl.getDocumentDOM().getTimeline();
  92. if (tl.findLayerIndex("as") == undefined){
  93.     tl.addNewLayer('as', 'normal' , true);
  94. } else {
  95.     tl.currentLayer = tl.findLayerIndex("as")[0];
  96. }
  97. tl.layers[tl.currentLayer].frames[0].actionScript = exportString.split('] , ];').join(']];') + "\n";
  98. // The following example tests the movie for the current document:
  99. fl.getDocumentDOM().testMovie(); // if you don't want to export to swf after the jsfl is ready, comment this line
  100. // end jsfl
RAW Paste Data