Skip to content

Instantly share code, notes, and snippets.

@fwextensions
fwextensions / gist:4759119
Created February 12, 2013 01:01
How to create a new layer at the top of the stack, add objects to it, and lock it.
var dom = fw.getDocumentDOM(),
currentLayerIndex = dom.currentLayerNum,
newLayerIndex;
dom.addNewLayer(null, false);
// currentLayerNum is set to the newly added layer
newLayerIndex = dom.currentLayerNum;
// put the new layer before the last layer. note that this won't work
@fwextensions
fwextensions / gist:4300987
Created December 15, 2012 23:42
The Adobe Fireworks JavaScript engine has an undocumented File class that has some useful features lacking in the documented Files object.
// to access a file, create a new instance of the File class by passing in
// a standard OS-style path to the constructor. I've only tested this on
// Windows, but a standard path on OS X should work, too.
var f = new File("C:\\test.txt");
// unlike the file references created by the Files object, these have some
// useful properties, like length, which is the file size in bytes
@fwextensions
fwextensions / gist:2927376
Created June 14, 2012 00:33
Code to get the number of chars and words in a text element
var r = [], t;
if (el && el.textRuns) {
t = el.textChars;
r = ["chars:", t.length,"words:", t.split(/\s+/).length];
}
r.join(" ");
@fwextensions
fwextensions / gist:2783196
Created May 24, 2012 18:10
Example of writing JSON-style info to a file
// ===========================================================================
try { (function() {
if (!fw.selection || !fw.selection.length) {
return;
}
var element = fw.selection[0],
info = {
name: element.name,
@fwextensions
fwextensions / gist:2713933
Created May 16, 2012 21:04
dojo in FW JS
// embed a local copy of the dojo JSON library, which has been changed
// to not depend on any other part of dojo. that way, we don't have to
// rely on external libraries. unlike Crockford's library, the dojo
// implementation doesn't change the prototypes of basic types, which
// caused problems for the Path panel, and possibly others.
var dojo = {};
dojo.fromJson = function(/*String*/ json){
return eval("(" + json + ")"); // Object
}
@fwextensions
fwextensions / gist:2631084
Created May 7, 2012 22:36
Code for listening to FW events
private const SupportedFWEvents:Object = {
onFwActiveDocumentChange: 1,
onFwActiveSelectionChange: 1,
onFwActiveToolChange: 1,
...
};
private function onPreinitialize() : void
{
// we need to register these callbacks early in the startup process.
var dp = [],
files = [];
// concat the two directories into one array of paths. note that the object
// returned by enumFiles isn't a real array, so we can't call concat on it.
files = files.concat(Files.enumFiles(fw.appSmartShapesDir),
Files.enumFiles(fw.appSmartShapeToolsDir));
for (var i = 0, len = files.length; i < len; i++) {
var file = files[i],
@fwextensions
fwextensions / gist:2052247
Created March 16, 2012 19:58
Decomposing a 2D transformation matrix to find the skew
/*
This code takes a 2D transformation matrix described as a one-dimensional array
(in column order, top to bottom and left to right) and decomposes it using the dojo
matrix library. This input matrix should produce a 45-deg X skew:
1 1 0
0 1 0
0 0 1
The output of decompose() looks like this:
@fwextensions
fwextensions / gist:1930404
Created February 28, 2012 07:32 — forked from poor666/gist:1930325
onMouseDown
onButtonDown = function(event)
{
event.result = [
["save", "enabled", false],
["Pass", "enabled", false],
["save", "label", waitingFrase()]
];
}
onButtonClick = function(event){
@fwextensions
fwextensions / gist:1174629
Created August 26, 2011 22:53
Importing a rich symbol
function insertSymbol(
inSymbolName,
inPath)
{
var dom = fw.getDocumentDOM();
var middleX = Math.round(dom.width / 2);
var middleY = Math.round(dom.height / 2);
try {
// first assume the symbol is already in the library and try to