Output (library)

Categories:Text

Overview

Summary

The Output library provides logging functionality, object introspection, and a variety of printing and formatting methods. You will typically use the library in development, to inspect variables, or perhaps to save data to file for reporting or logging tasks.

Contents

API

props(obj, output)

Converts a typical [object Object] string into an [object Class value="1" property="2"] string

Parameters:

  • obj Object Any object that can be converted to a String
  • output Boolean An optional Boolean idicating to output the result to the Output panel

Returns:

  • String A String representation of the object and its properties

Debug the contents of an object and output to the Output panel:

var obj = {a:null, b:1, c:'Hello'};
trace(Output.props(obj));
[object Object a=null b=1 c="Hello"]

list(arr, properties, label, output)

Lists the properties of an object in a human-readable format

Parameters:

  • arr Object An object whose properties you wish to list
  • arr Array An Array of objects with selected properties you wish to list
  • properties String An optional property to list, defaults to 'name'
  • properties Array An optional Array of properties
  • label String An optional String label, defaults to "List"
  • output Boolean An optional boolean to indicate output type: true=debug, false=return, undefined=output

Returns:

  • String A String list of the object's properties

List the items of the current selection:

Output.list($selection);
List: Array (depth:1, objects:0, values:4, time:0.0 seconds)
--------------------------------------------------------------------------------
array => Array
	 0: "circle_01"
	 1: "star"
	 2: "square"
	 3: ""

List several properties of a an array of items:

Output.list($library.items, ['name', 'timeline', 'itemType']);
List: Array (depth:2, objects:10, values:10, time:0.0 seconds)
--------------------------------------------------------------------------------
array => Array
	[0] => Array
		 0: "star graphic"
		[1] => Timeline
		 2: "movie clip"
	[1] => Array
		 0: "oval_graphic"
		[1] => Timeline
		 2: "movie clip"
	[2] => Array
		 0: "star"
		[1] => Timeline
		 2: "movie clip"
	[3] => Array
		 0: "oval"
		[1] => Timeline
		 2: "movie clip"
	[4] => Array
		 0: "rectangle"
		[1] => Timeline
		 2: "movie clip"

Note that Output.list() has also been aliased as a global function, list():

list($selection);

inspect(obj, $depth, $label, $debug, $filters, $callback)

Output object in hierarchical format

Parameters:

  • obj Object Any Object or value
  • $depth Number An optional max depth to recurse to (defaults to 3)
  • $label String An optional String label (defaults to "Inspect")
  • $debug Boolean An optional boolean to indicate output type: true=debug, false=return, undefined=output
  • $filters Object An optional filter object to tell the outputter what to print, ie {'function':false, 'xml':false}. Allowed types: ['object', 'string', 'array', 'number', 'xml', 'object', 'boolean', 'function', 'undefined', 'null']
  • $callback Function An optional output function in case you want to do any custom processing of the data. It is called once per output line.

Returns:

  • String A String hierarchy of the object's properties

The $ arguments of this method are derived using parameter type-shifting, that is, each argument is a different datatype, so they can be supplied in any order. This leaves you flexible to apply some or many properties as you see fit, without having to enter default values.

Inspect the current library items, with a custom label, and limiting the inspection depth to 3 levels:

Output.inspect($library.items, 'Library items', 3);
Library items: Array (depth:4, objects:39, values:120, time:0.0 seconds)
--------------------------------------------------------------------------------
array => Array
	[0] => SymbolItem
		[timeline] => Timeline
			 name: "star graphic"
			[layers] => Array
				[0] => Layer
			 frameCount: 1
			 currentFrame: 0
			 layerCount: 1
			 currentLayer: 0
			[bindings] => Array
		 symbolType: "movie clip"
		 sourceFilePath: ""
		 sourceLibraryName: undefined
		 sourceAutoUpdate: undefined
		 scalingGrid: false
		[scalingGridRect] => Object
			 left: -2147483.648
			 top: -2147483.648
			 right: -2147483.648
			 bottom: -2147483.648
		 itemType: "movie clip"
		 name: "star graphic"
		 linkageExportForAS: false
		 linkageExportForRS: false
		 linkageImportForRS: false
		 linkageExportInFirstFrame: undefined

		 // additional properties truncated

Note that Output.inspect() has also been aliased as a global function, inspect():

inspect($selection);

table(arr)

Convenience function to Table.print() to output value in tabular format

Parameters:

  • arr array An Array of values

Returns:

  • String The output of the print() call

List the properties of the Preset panel in table format:

Output.table(app.presetPanel.items);
+-----------+----------+-------+-------------------------+-------+----------------------------------------+
| isDefault | isFolder | level | name                    | open  | path                                   |
+-----------+----------+-------+-------------------------+-------+----------------------------------------+
| true      | true     |     0 | Default Presets         | false | Default Presets                        |
| true      | false    |     1 | bounce-in-3D            | true  | Default Presets/bounce-in-3D           |
| true      | false    |     1 | bounce-out-3D           | true  | Default Presets/bounce-out-3D          |
| true      | false    |     1 | bounce-smoosh           | true  | Default Presets/bounce-smoosh          |
| true      | false    |     1 | fly-in-blur-bottom      | true  | Default Presets/fly-in-blur-bottom     |
| true      | false    |     1 | fly-in-blur-left        | true  | Default Presets/fly-in-blur-left       |
| true      | false    |     1 | fly-in-blur-right       | true  | Default Presets/fly-in-blur-right      |
| true      | false    |     1 | zoom-in-3D              | true  | Default Presets/zoom-in-3D             |
| true      | false    |     1 | zoom-out-2D             | true  | Default Presets/zoom-out-2D            |
| true      | false    |     1 | zoom-out-3D             | true  | Default Presets/zoom-out-3D            |
| false     | true     |     0 | Custom Presets          | true  | Custom Presets                         |
| false     | false    |     1 | 10 frame on & off       | true  | Custom Presets/10 frame on & off       |
| false     | false    |     1 | 10 frame scale in       | true  | Custom Presets/10 frame scale in       |
| false     | false    |     1 | 25f in 25f hold 10f out | true  | Custom Presets/25f in 25f hold 10f out |
| false     | false    |     1 | Scale up and wobble     | true  | Custom Presets/Scale up and wobble     |
+-----------+----------+-------+-------------------------+-------+----------------------------------------+

folder(value, depth, output)

View the hierarchy of a folder

Parameters:

  • value String A valid folder path
  • value Folder An existing folder object
  • depth Number An optional max depth to recurse to (defaults to 3)
  • output Boolean An optional boolean to indicate outputting or not (defaults to true)

Returns:

  • String The String hierarchy of the folder

Output the user folder in hierarchical format, limiting to 3 levels deep:

Output.folder('user', 3, true);
/user
	/assets
		/readme.txt
	/config
		/data
			/readme.txt
		/settings
			/readme.txt
			/test.xml
			/user.xml
			/xjsfl.xml
		/templates
			/readme.txt
	/jsfl
		/bootstrap.jsfl
		/learning
			/test script 01.jsfl
		/libraries
			/readme.txt
		/snippets
			/Demo
			/Development
			/Instances
			/Library
			/Stage
	/temp
		/dom.txt
		/readme.txt
	/ui
		/readme.txt

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>