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