Skip to content

Instantly share code, notes, and snippets.

try {
(function()
{
if (fw.selection.length == 0) {
alert("To use this command, first select a group from which the Smart Resize auto shape should be detached.");
return;
}
var dom = fw.getDocumentDOM();
@fwextensions
fwextensions / gist:77340
Created March 11, 2009 05:57
Fireworks: Saving and restoring the current selection
// make a copy of the current selection by concatenating it
// with an empty array
var originalSelection = [].concat(fw.selection);
for (var i = 0, len = originalSelection.length; i < len; i++) {
// change the selection as needed
}
// restore the original copy of the selection
fw.selection = originalSelection;
/*
The regular expression below is used in John Resig's HTML parser written in JS, which
I was trying to use in an Adobe Fireworks extension to construct tables from HTML
source. In a browser, from IE6 on up, it produces:
[<table border="1">,table, border="1",""]
In Fireworks' JS parser, derived from Mozilla code released in *1998*, it produces:
null
@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
@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: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:
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: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.
@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: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,