JSFL bugs and gotchas

Categories:JSFL Knowledgebase



This page is a drop-box of JSFL bugs and gotchas, gathered from xJSFL development, a well as round the web.

They pretty much all concern vanilla JSFL, and have been worked-around where possible in the framework. Where they haven't they may be in future releases. Not all errors have been checked for validity, nor have they been checked against all CS versions.

For your information:

  • Bugs refer to actual Flash bugs - features that are broken or don't work correctly
  • Gotchas refer to features that might not work the way you expect, but they do work
  • Tips provide clever ways to do things that might not otherwise be possible

Information about what's new in each CS version can be found below:




Shape selection bug

Shape deletion bug:

Seems impossible to properly set the matrix of a bitmap fill:


Selection is always ordered in reverse!

document.selection adds to, instead of replacing the current selection

isGroup property is available for any type of stage Element, not only for shapes:

Distribute to Layers moves elements unless snap to pixels is turned off:


You can set the element.selected property to add and remove items from the current selection

Update stage after any script operation using: fl.getDocumentDOM().livePreview = true

Create individual movieclips for layers / shapes by using distribute to layers first: fl.getDocumentDOM().distributeToLayers();

Setting element widths and heights using a matrix:

Set stroke to none:



setSelectedLayers(index, replace) – setting replace = false actually TOGGLES the layer selection

setSelectedFrames(start, end, replace) – setting replace = false actually TOGGLES the frame selection

timeline.setSelectedFrames() does not always work:


To find out if a frame is a keyframe, compare the frame's startFrame against the frame index you want to check against: keyframe = frame.startFrame == index



library.addItemToDocument() resets the current library selection, but doesn't update the Library UI. The workaround is to grab the selection before adding items, then reset it afterwards.

library.selectItem() randomly doesn't work per session - the items remain unselected

library.updateItem() crashes Flash CS3

Bitmap linkage names do not update when changed:


library.findItemIndex() returns an empty Array (should be a Number) if the item is not found

Library items are listed in creation order. They needed to be sorted by comparing item.name.toLowerCase() first. Renames or moves are not carried across for subsequent operations


Import bitmaps and sound using JSFL: http://www.bit-101.com/blog/?p=547




Relative file URIs are only relative to the current fla - NOT the currently-running JSFL script (although, often, this won't work either)

FLfile.browseForFolderURL() returns the name of the Mac hard drive, which causes files to have the wrong URL:

This post says that scripts can be run relatively, but that doesn't seem to be the case in CS4+


fl.runScript() needs a fully encoded string including %20 for spaces

FLfile.write uses ANSI not UTF-8:


Execute commands from the command line:

FLfile.runCommandLine('"path/to/file.xml"') // PC 
FLfile.runCommandLine('exec "path/to/file.xml"') // Mac

Copy directories with JSFL

Possibly use String.fromCharCode(13,10) to write \r\n newlines



Any syntax errors inside scripts run with runScript() will fail silently, even with try/catch inside or outside. See the support section on Debugging for more information and workarounds.



  • Scripts executed from the Commands menu makes are persistent – per document only.
  • Scripts executed externally, or via fl.runScript() or eval() are available only while the calling script executes
  • Running an open JSFL script in Flash IDE is the same as running it externally


  • Each document and panel runs in its own scope

Using var or function makes values local in external scripts. The workaround (especially for classes) is to state the variable or function name globally:

// bad
	var test = 1;
	function Test(){ }

// good
	test = 1;
	Test = function(){ }

	var test = new Test(); // is remembered

// notes
	// Note that Test = function seems to return a  self-executing function as the constructor source: "(function  () {})"
	// function Test() will  return "function Test()"

Note that const s cannot be redeclared, or an error is thrown, so it's easier not to use them in development.


Disable long script running time warning: use fl.showIdleMessage(false)



Can't empty a form field by setting it to ""

Can't check checkboxes / radios using JSFL

Seems to be an issue when getting the value of one colorchip in a change/create handler. Other colorchips are then deleted.

It seems impossible to write JSFL (i.e. if(x && x.y){ ... } ) in a XUL script tag unless you use a CDATA section, but it seems to stop alert() running. Needed to use oncreate="" to work around it

Opening a XUL dialog from a script seems to have some kind of hidden time limit that will cause the calling script to fail silently if the dialog is not accepted in an arbitrary time (seems to be about 20 seconds or so)


XUL panels fail to instantiate if they can't find the XUL file with the error "xmlPanel: Argument number 1 is invalid"


Communicating between XUL and AS



ActionScript trace() will NOT trace to the output panel when running live in an SWF panel ! You should instead use:

MMExecute("fl.trace('" + value +  '")");


To reload a panel, the easiest thing is to set a shortcut key to the current panel – CTRL + ` is a quick one when developing



Array.sort() doesn't sort numbers! Which includes timeline.getSelectedLayers() that returns an array of selected layer indices. Use Utils.sort() to sort arrays, or the xJSFL object extension timeline.selectedLayers to get selected layers (as layers, and in order).


Events are pretty crappy in JSFL. See the Events page for more information

fl.createDocument() does not dispatch a "documentCreated" event

fl.saveDocument() does not dispatch a "documentSaved" event


Use XML to build multiline strings, rather than concatenate lots of '\n' strings:

var text = <text>
This is
some multiline
text. Yay!



SpiderMonkey does not support E4X filtering

You can also use (doesn't work with delete):

var b =  a.*.(function::attribute("id") == 'b');


Mac: fl.saveDocumentAs()

Can't change publish profiles


Bug in JSFL fl.findObjectInDocByType in Flash CS3



Exporting Components / SWC – single .fla but multiple .swc - set all to NOT export in the first frame!

Skinning the Flash CS3 components

Export multiple swc using JSFL

Export swc from FlashDevelop


Extending  native objects causes an IK error in CS4. For example, something as basic as this will cause the output panel to fill up with randomly produced IK Tool errors any time you click or interact with the stage

Object.prototype.prop = 1;

I suspect that internally to the IK tool, the developer is iterating over an object using a for..in loop, and either not checking using hasOwnProperty(), or should be using a for loop.

My solution is to disable the IK tool by removing it from various folders in the  installation:

  • In both the following folders...
    F:\Users\<user>\AppData\Local\Adobe\Flash  CS4\en\Configuration\Tools
    C:\Program Files (x86)\Design\Adobe Flash CS4\Common\First Run\Tools
  • ...move IK, IKBridgeLink.jsfl and Rig.jsfl to a new subfolder called "disabled".
  • In the user folder, comment-out the node in IK toolConfig.xml
  • Finally, restart Flash

The real solution is to either get Adobe to patch the offending script, or to provide a JSFL script to update the files in each user's installation.

BUT... in all honestly, you shouldn't be extending native objects anyway :)

4 Responses to JSFL bugs and gotchas

  1. yoni says:

    this summary has been very helpful, thank you.

  2. Michael says:

    Not being able to sort an array of numbers is very annoying, I had to convert the numbers to strings, then I was able to sort. After turning the strings back into numbers I was good to go.

  3. Dave Stewart says:

    Arrays are sorted by string by default in JavaScript. Use Utils.sort() to get around this: http://www.xjsfl.com/support/api/utils/utils#sort

  4. Ben says:

    This is really great, thanks for the effort putting it together

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>