User Guide Cancel

Creating custom Components: Examples

  1. Adobe Animate User Guide
  2. Introduction to Animate
    1. What's New in Animate
    2. Visual Glossary
    3. Animate system requirements
    4. Animate keyboard shortcuts
    5. Work with Multiple File Types in Animate
  3. Animation
    1. Animation basics in Animate
    2. How to use frames and keyframes in Animate
    3. Frame-by-frame animation in Animate
    4. How to work with classic tween animation in Animate
    5. Brush Tool
    6. Motion Guide
    7. Motion tween and ActionScript 3.0
    8. About Motion Tween Animation
    9. Motion tween animations
    10. Creating a Motion tween animation
    11. Using property keyframes
    12. Animate position with a tween
    13. How to edit motion tweens using Motion Editor
    14. Editing the motion path of a tween animation
    15. Manipulating motion tweens
    16. Adding custom eases
    17. Creating and applying Motion presets
    18. Setting up animation tween spans
    19. Working with Motion tweens saved as XML files
    20. Motion tweens vs Classic tweens
    21. Shape tweening
    22. Using Bone tool animation in Animate
    23. Work with character rigging in Animate
    24. How to use mask layers in Adobe Animate
    25. How to work with scenes in Animate
  4. Interactivity
    1. How to create buttons with Animate
    2. Convert Animate projects to other document type formats
    3. Create and publish HTML5 Canvas documents in Animate
    4. Add interactivity with code snippets in Animate
    5. Creating custom HTML5 Components
    6. Using Components in HTML5 Canvas
    7. Creating custom Components: Examples
    8. Code Snippets for custom Components
    9. Best practices - Advertising with Animate
    10. Virtual Reality authoring and publishing
  5. Workspace and workflow
    1. Creating and managing Paint brushes
    2. Using Google fonts in HTML5 Canvas documents
    3. Using Creative Cloud Libraries and Adobe Animate
    4. Use the Stage and Tools panel for Animate
    5. Animate workflow and workspace
    6. Using web fonts in HTML5 Canvas documents
    7. Timelines and ActionScript
    8. Working with multiple timelines
    9. Set preferences
    10. Using Animate authoring panels
    11. Create timeline layers with Animate
    12. Export animations for mobile apps and game engines
    13. Moving and copying objects
    14. Templates
    15. Find and Replace in Animate
    16. Undo, redo, and the History panel
    17. Keyboard shortcuts
    18. How to use the timeline in Animate
    19. Creating HTML extensions
    20. Optimization options for Images and Animated GIFs
    21. Export settings for Images and GIFs
    22. Assets Panel in Animate
  6. Multimedia and Video
    1. Transforming and combining graphic objects in Animate
    2. Creating and working with symbol instances in Animate
    3. Image Trace
    4. How to use sound in Adobe Animate
    5. Exporting SVG files
    6. Create video files for use in Animate
    7. How to add a video in Animate
    8. Draw and create objects with Animate
    9. Reshape lines and shapes
    10. Strokes, fills, and gradients with Animate CC
    11. Working with Adobe Premiere Pro and After Effects
    12. Color Panels in Animate CC
    13. Opening Flash CS6 files with Animate
    14. Work with classic text in Animate
    15. Placing artwork into Animate
    16. Imported bitmaps in Animate
    17. 3D graphics
    18. Working with symbols in Animate
    19. Draw lines & shapes with Adobe Animate
    20. Work with the libraries in Animate
    21. Exporting Sounds
    22. Selecting objects in Animate CC
    23. Working with Illustrator AI files in Animate
    24. Applying blend modes
    25. Arranging objects
    26. Automating tasks with the Commands menu
    27. Multilanguage text
    28. Using camera in Animate
    29. Graphic filters
    30. Sound and ActionScript
    31. Drawing preferences
    32. Drawing with the Pen tool
  7. Platforms
    1. Convert Animate projects to other document type formats
    2. Custom Platform Support
    3. Create and publish HTML5 Canvas documents in Animate
    4. Creating and publishing a WebGL document
    5. How to package applications for AIR for iOS
    6. Publishing AIR for Android applications
    7. Publishing for Adobe AIR for desktop
    8. ActionScript publish settings
    9. Best practices - Organizing ActionScript in an application
    10. How to use ActionScript with Animate
    11. Accessibility in the Animate workspace
    12. Writing and managing scripts
    13. Enabling Support for Custom Platforms
    14. Custom Platform Support Overview
    15. Working with Custom Platform Support Plug-in
    16. Debugging ActionScript 3.0
    17. Enabling Support for Custom Platforms
  8. Exporting and Publishing
    1. How to export files from Animate CC
    2. OAM publishing
    3. Exporting SVG files
    4. Export graphics and videos with Animate
    5. Publishing AS3 documents
    6. Export animations for mobile apps and game engines
    7. Exporting Sounds
    8. Best practices - Tips for creating content for mobile devices
    9. Best practices - Video conventions
    10. Best practices - SWF application authoring guidelines
    11. Best practices - Structuring FLA files
    12. Best Practices to optimize FLA files for Animate
    13. ActionScript publish settings
    14. Specify publish settings for Animate
    15. Exporting projector files
    16. Export Images and Animated GIFs
    17. HTML publishing templates
    18. Working with Adobe Premiere Pro and After Effects
    19. Quick share and publish your animations
  9. Troubleshooting
    1. Fixed issues
    2. Known issues

 

Use this article to understand a sample HTML5 custom component.

This article describes how to create custom components. The first example describes the image component (which is also supplied with Animate) and the process to understand the framework and the steps involved in development. The second example describes how to wrap any existing UI component (like jQueryUI) and import it within Animate.

  1. Creating a DOM image component

    Create a category called My Components

    a. Create a folder called mycomponents under <HTML5Components> folder in first run

    b. Download the attached myimage.zip file and extract the contents under the

        mycomponents folder.

    Download

    c. Restart Animate.

Directory structure within mycomponents folder
Directory structure within mycomponents folder

You should now see a new category called “My Components” in components folder and a new component called My Image under it. You can drag-and-drop this on stage, set the image source property and publish the movie to see the custom component in action. 

Component Metadata - components.js

Components.js code
Components.js

Please note that the category is set to CATEGORY_MY_COMPONENTS. The names for each of the properties are also using similar keys. This is the key for the localized string for the category name. If you open strings.json from the locale folder, you will see the following entries.

 The most common error while editing this file is having an unnecessary trailing comma for the last element in the array.

Category details
Category details

The value of the icon field is set to Sp_Image_Sm. If you go to the assets folder you will notice the following two pngs under it with the prefix Sp_Image_Sm.

Value of the icon field
Value of the icon field

These are the icons for dark and light UI.

The value of the ‘source’ field in components.json, its set to ‘src/myimage.js’. 

(function($) {    

// Register a component with the className: my.Image,
 // and prototype with the following overrides 
 // getCreateOptions
 // getCreateString
 // getProperties
 // getAttributes
    $.anwidget("my.Image", {
         options: {
   'visible': true,
   'position': 'absolute'
         },
  _props: ["left", "top", "width", "height", "position", "transform-origin", "transform"],
  
_attrs: ["id", "src", "alt", "class", "border"],
  
// Return a unique ID with the prefix image
  // _widgetID is a global declared in anwidget
  // This id is used only if the user has not set any instance ID for the component in Animate
  // Otherwise the user configured name is used
  getCreateOptions: function() {
   return $.extend(this.options, { 'id': "image" + _widgetID++ });
  },
  
// Return the string for creating the DOM element
  // For image we just need to create the <img> tag
  getCreateString: function() {
   return "<img>";
  },
  
// Set of configurable properties
  getProperties: function() {
   return this._props;
  },
  
// Set of configurable attributes
  getAttributes: function() {
   return this._attrs;
  }    
 });   
})(jQuery);

You can follow the comments in the code to understand it easily. 

Please feel free to take a look at the source for the other components which are supplied with Animate. In most of the cases you can use one of these as the starting point and then configure it for your own requirements.

Wrapping a jQuery-UI component

This section describes how to wrap a jQuery-UI widget and use it in Animate. The same concepts can be used to wrap any other existing component from any other UI framework.

Let us understand the packaged DatePicker component with Animate which is a jQuery-UI widget. Download and extract the contents of the following archive and use it for your reference.

Download

Structure of the extracted content
Structure of the extracted content

The folder named jquery-ui-1.12.0 is the source for the jQuery UI framework which contains the original DatePicker widget and its resources like images and css to wrap and use in Animate like any other HTML5 Component. This is required only for local preview, when you use “hosted libraries” in Publish settings, you have the option to use the cdn to download the dependent sources. 

Components.js code
Components.js

There are two default dependencies, jQuery and anwidget.js. Since anwidget.js is not on the CDN, we do not have any CDN entry for the same.

The next set of entries are for the other resources required for loading the datepicker widget from jquery ui. If you are wrapping any widget from any other library, you can similarly specify the set of dependencies for the same. These dependencies are downloaded before the component is initialized.

In the properties section, we have only exposed one property called label, which is bound to the label property for the date-picker component. Similarly, we can expose the other properties too, whichever we want the user to be able to configure in Animate’s authoring environment. At runtime, each of these will be available as a key-value pair in the options array for the instance. We can extract the configured value and apply that at runtime.

Main source file: src/datepicker.js.
Main source file: src/datepicker.js.

Sections that differ from the example

  1. getCreateString:

    The datepicker widget from jQuery-UI takes such an input text element and converts it to a date-picker element at runtime. Therefore, we initialize the DOM accordingly.

  2. attach:

    We need to override this function for this widget. This API is called whenever the element is being attached to the DOM. However, because of the way the underlying runtime (in this case createjs) works, this API may be called multiple times during a frame span.

    We remember the attached state of the underlying element and then call the base class’s attach API (using this._superApply(arguments)). If this is the first time we are attaching the element to the parent DOM then we use the underlying jQuery-UI widget’s call to convert our component’s DOM to a datepicker. See - https://jqueryui.com/datepicker/

    Most of the javascript widgets work in a similar fashion. You can use the same technique to wrap any component of your choice and bring it into Animate in the same manner.

  3. Update: We override update and apply the css properties to the container div and attributes to the real DOM element.

     When you override APIs like attach, detach or update, evaluate the base class’s default implementation and call the base implementation at appropriate time otherwise the component initialization may fail.

 Adobe

Get help faster and easier

New user?