Use this article to learn how to create custom components for HTML5 canvas.

Animate CC ships with a set of default components. However, these are insufficient for your project. This topic helps you understand how to create custom HTML5 Components for Animate CC.

A component definition consists of three major parts:

  • Metadata: Provides information about the component such as display name, version, set of configurable properties, icon, and so on. This is captured in a file called components.js. You can group the components as a category and  this file allows you to provide the meta-data for all components in a category.
  • Source: Provides information about the actual component source. This is embedded at runtime when you preview or publish a movie using components.
  • Assets: Provides information about any runtime dependency such as like JavaScript library or CSS or runtime assets and icons. The assets can be used in the Animate authoring environment.

Note:

A component definition also has localization-related resources.

componentsJS
Sample folder configuration for a custom component category

Animate CC checks the following folders for any custom HTML5 Components and loads them on launch:

• Windows:

<AppData>/Local/Adobe/Adobe Animate CC 2017/en_US/Configuration/HTML5Components

 

• MAC:

 

~/Library/Application Support/Adobe/Animate CC 2017/en_US/Configuration/HTML5Components/

Note:

The above folder path is applicable for US English. If you are using Animate in any other language, look for your language specific folder name replacing en_US.

For each folder within the location that contains the file ‘components.js’, Animate CC creates a category, and loads all the components within.

Component Metadata

The metadata of the Component is captured in a file called components.js which is placed inside a separate folder within HTML5Components directory. 

metadata-code
Sample metadata for a video component.

Components.js

Components.js

is a JSON file that contains the following sections:

  • Category: Name in the Components Panel for this set of components and can be localized.
  • Components: Array where each entry contains the metadata about a component. The above sample has only one element in the array. The metadata has following sections:

Name

Required

Description

ClassName

Yes

Class name of the component specified in the source file. The class name supports one level of namespaces. For example, Video.

 

Version

No

Version number of the component. This is used for future component upgrades. However, the flow is not defined at this point of time.

Source

Yes

Relative path of the component’s main source file. More details are provided on what does the source contain in the next section.

Icon

No

Relative path for the icon for the component. This icon is used in the components panel and on stage when any instance is created for the component along with its name. If none is provided a default icon will be used.

You can specify the png name of the icon to be loaded (typically 32x32). Or else, if you want to support different icons for light UI and dark UI then provide two .pngs with the following naming convention:

 

custom_icon_N.png – Icon for dark UI

custom_icon_D.png – Icon for light UI

 

and just specify the name ‘custom_icon’ as the value for this field. The suffixes are automatically appended based on the current user setting.

Dimensions

No

Default size for the component instances. Whenever user drags and drops a component from Component panel to stage, a new instance is created. This field specifies the default initial size for the component instance. The value should be an array [width, height]. If there is no value specified, then Animate picks up a default size. Also Animate restricts the size to be within [2,2] to [1000, 1000] range.

Dependencies

No

The set of dependencies for the component. This is an array where each entry provides the relative path for a local source (with key = “src”) and CDN path (with key=’cdn’). The CDN path is not mandatory. This path is used when you use hosted libraries in the publish settings. Otherwise the local source will be used when you preview or publish.

 

Do note the relative path used in the example above (video). Its loading the dependencies from one level above, which allows us to share some dependencies across multiple component sets.

 

Properties

Yes

This is an array of properties. When you create any instance of this component on stage, the set of properties configured here will be automatically shown in the PI. Users of this component can configure those properties in Animate CC and the configured properties are made available during instantiation of the component at runtime.

 

Each property entry contains the following keys:

  1. name: The name shown in the PI for this property. This should be a user-friendly name. This can be localized.
  2. variable: The internal name used for this property. The configured values will be available with this variable name at runtime. More details on this will be covered in later sections.
  3. Type: This specified the type of the property. Animate CC allows the following types:
    1. Boolean  - Checkbox in PI
    2. Number  - Numeric box in PI
    3. String    - Text box in PI
    4. List        - Allows user to configure an array of values.
    5. Collection- Allows the users to configure a list of <key, value> pairs. (See combo box)
    6. File Path  - Allows the user to browse and select any local file. The string value is supplied at runtime. The file is automatically copied in the published output in ‘assets’ folder and the relative path is made available at runtime.
    7. Image Path - Allows the user to browse and select any image. The file is automatically copied in the published output in the configured images folder and the relative path is made available at runtime.
    8. Video Content Path – Allows the user to browse and select any web format video source (mp4, ogg, ogv, webm). The configured asset is copied to ‘videos folder in the published output.
    9. Color - Color Picker in PI

4.       Default: Default value of the property. The default should be of same type as the type of the property.

Component Source

Each component should have a source file associated which provides code to handle the following:

  • Creation of component instance at runtime with configured set of property values
  • Attaching and Detaching to the DOM.
  • Property updates in every frame

A base class is provided and a utility function in the file anwidget.js for easier development of custom components. This interface will be enhanced in future but will be backward compatible. Currently only DOM- based components are supported; however support for canvas based components will be extended. Currently only widgets are supported; however, the framework will be enhanced to support attaching behaviors (non-ui components).

The file anwidget.js  is present under HTML5Components/sdk folder in your first run folder. It provides a base class AnWidget for custom components and a utility method $.anwidget(<className>, {Object Prototype}) for registering a custom component. The current implementation uses jQuery, so jQuery is always added as a dependency whenever you use the services provided by a widget. However, if you do not want to add an implicit dependency on jQuery, then you may need to implement a Component class without jQuery which provides the same interface as a Widget.

 

AnWidget
HTML template

The html contains these sections (excluding the preloader div) by default:

animation_container
Default HTML sections (excluding the preloader div)

Do note that the previous figure illustrates the order in which the elements are added in the DOM. Thus the dom_overlay_container div is shown above the canvas.

Note:

Do not change the ID of the dom_overlay_container div as in our first release, there are a couple of features which depend on this ID like code snippets.

As shown in the previous illustration, the dom_overlay_container div is shown on top of the canvas as an overlay. To make sure that the mouse events are propagated properly to the underlying canvas too, we use the CSS property {pointer-events: none} for this div so that mouse events are propagated to the underlying canvas. All the component instances which are configured in Animate CC in your project are instantiated and attached as a child of this dom_overlay_container div. The relative ordering of the component instances are maintained at runtime, but currently all the component instances are always shown as an overlay. We set {pointer-events: all} for all the component instances at runtime so that they also receive the mouse events.

Component lifecycle

component_lifecycle
Component lifecycle

  1. The component instance is created when the DOM is being constructed for the container.

  2. The instance is then attached to the DOM when the playhead reaches the frame where the component instance is used. It then attaches an update handler which is called on every tick at runtime. The component also fires an event ‘attached’ at this time with the following event data {id: id_of_the_instance} on the parent element.

  3. The Properties are updated in every update callback. All the property updates are cached and applied once during a tick handler. Currently custom property tweens are not supported. Only the basic properties such as transform and visibility are updated.

  4. When the playhead reaches a frame where component instance is removed, we detach it from the DOM. A ‘detached’ event is fired this time on the parent element.

The base class is called $.AnWidget and provides the following overrides:

Name

Mandatory

Description

getCreateOptions()

No

Returns any options which the component wants to be applied during component instantiation. A typical override generally uses this to assign a unique ID to every instance by making use of the global variable _widgetID. The example in the next section will make its usage clear.

getCreateString()

Yes

Return the string for your DOM instance creation. This string is passed to jQuery to create the actual DOM element which is attached later to the base DOM.

 

For example, for an image component this should return “<image>”.

 

At runtime the element is created and the reference to the jQuery wrapper is stored as follows in the component instance:

 

this._element =  $(this.getCreateElement())

 

// this._element – jQuery wrapper for the underlying DOM element created.

 

We can also create composite elements; the details will be covered in an examples section.

getProperties()

No

Returns an array of configurable CSS property names. Typically, this matches with all the properties you configured in components.json

 

For example, for the video component this array contains the following entries:

 

["left", "top", "width", "height", "position", "transform-origin", "transform"]

getAttributes()

No

Returns an array of configurable attributes. Typically, this matches with all the attributes that you are permitted to configure in components.json

 

For example, for the video component this array contains the following entries:

 

["id", "src", "controls", "autoplay", "loop", "class"]

attach(parent)

No

This function is called whenever the component instance is about to be attached to the ‘parent’ DOM element.

 

The default implementation does the following (and some more stuff):

 

// Appends the element to the parent DOM

$(parent).append(this._element);

 

//Stores the ref in this._$this

this._$this = $(this._element);

 

//Calls force update to apply all properties

this.update(true);

this._attached = true;

 

//Triggers the attached event on parent

$(parent).trigger("attached", this.getEventData("attached"))

 

You do not need to override this function. However, for composite elements we may need to override it. More details will be covered in the examples section.

 

Note: You can use this._superApply(arguments) to call any base class method from any override.

detach()

No

This function is called whenever the component instance is about to be removed from the DOM. The default implementation does the following:

 

//Removes the element from the DOM

this._$this.remove();

//Triggers the detached event on parent

$(parent).trigger("detached", this.getEventData("detached"));

setProperty(k,v)

No

This function is used to set any property for the instance. These changes are cached and are applied at once during the call to update() every frame for every property which is dirty.

update(force)

No

This function is called every frame when the component is part of DOM and is visible. The default implementation applies all the CSS properties and attributes which have changed or if force parameter is true.

show()

No

Shows the element instance. You typically don’t need to override this, but for composite elements you may need to.

hide()

No

Hides the element instance. You typically don’t need to override this, but for composite elements you may need to.

getEventData(e)

No

Returns any custom data for the event with name ‘e’. The default implementation passes the data {id: instance_id} for attached and detached events.

destroy()

No

Frees the memory when the component instance is detached from DOM. You typically don’t need to override this.

applyProperties(e)

No

Helper API for applying the CSS properties to the jQuery wrapper e.

applyAttributes(e)

No

Helper API for applying the attributes to the jQuery wrapper e.

Localization

The category string, component display name and property name can be localized. Create a file called strings.json in a folder with the name locale under the components folder. Provide the key-value pairs for all the strings to be localized and use the key in the components.js. For other locales, you need to provide the strings in the corresponding folders under the locale folder.

localization
.json string

Package and distribute custom HTML5 components

Animate developers or designers can enable animators to install and use components without coding, by providing ready-to-use packaged components. Previously, animators had to learn file structures, do programming, and manually move the files to specific folders to activate the HTML5 extensions.

Prerequisites

Before packaging your component, create an MXI file with the metadata of source and destination path of components. For example,

<file source="jquery-ui-1.12.0" destination="$FLASH\HTML5Components\jQueryUI\" file-type="ordinary" />

This source and destination file information is required to enable extensions utility for accurate installation of your component.

Packaging components

To package the HTML5 custom components, perform the following steps: 

  1. To create an MXI file, enter the content similar to the sample abc.mxi file using a text editor and save it with an MXI extension.

    Download

    Download

  2. Add your MXI component file and other associated files in a folder.

    Add-MXI-file-to-component
  3. Create a ZXP extension zip file by using the CC Extensions signing tool (ZXPSignCmd.exe). Use the following commands in ZXP Sign Command tool to create a ZXP file:

    1. Create a self-signed certificate by using the -selfSignedCert option.

    You can skip this step if you already have a certificate.

    Self-signature
    ZXPSignCmd -selfSignedCert US NY MyCompany MyCommonName password FileName.p12

    FileName.p12 file is generated in the current folder.

    2. Sign the extension using the following command: 

    Create-ZXP-file
    ZXPSignCmd -sign projectName projectName.zxp FileName.p12 password

    projectName is the name of the Extension Project. In the current folder, a file with the name projectName.zxp is generated.

Distribute components

You can distribute this projectName.zxp packaged component file to any of the Animate users.

Note:

Adobe recommends that you distribute your products through the Adobe Add-ons website. You can distribute add-ons publicly (free or paid) or privately (free to named users). Learn more about sharing products privately.

Install distributed components

Animate designers or developers can install the distributed ZXP file component by using the Manage Extensions utility.

For more information, see Install distributed components

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy