Adobe Animate Team Blog

The latest news, tips and insights directly from the Animate team

Tag

HTML5

Mar 30, 2016/General/

Using Animate CC HTML5 Canvas Templates with Multiple Publish Profiles

The ability to publish to HTML5 Canvas from Animate CC (and Flash Professional before it) is nothing new… however, with the release of Animate CC we now have a number of additional options when managing how a project gets published – especially in terms of how the HTML output is constructed.

 

HTML5 Canvas Output

When publishing to HTML5 Canvas from Animate CC, the resulting HTML file is hugely important in terms of the project’s ultimate destination. This can be clearly seen in terms of the differing specifications which ad distribution networks expect content producers to conform to when submitting their projects.

 

figure1

Figure 1. We are using an HTML5 Canvas document for this project.

 

In the Properties Panel, we can easily see it specified that we are working on an HTML5 Canvas Document. You might also notice that the Publish Profile is listed as Default. This is an often overlooked features of Animate CC and we will be examining it later in this article.

 

figure2

Figure 2. The Properties Panel indicates the type of document and Publish Profile being used.

 

Before moving on, if we go ahead and test our document in the web browser by choosing Control > Test, we’ll see the result of this Default Publish Profile. The canvas element which is our published project is aligned to the upper left and the HTML background color is a sad grey.

 

figure3

Figure 3. Our content rendered using the default Publish Template.

 

The good news is that it doesn’t have to be this way! Let’s now go ahead and click on Publish Settings in the Properties Panel to access all of our document publish options.

 

HTML5 Canvas Templates

The first thing to do if you want to create a template of your own is to export the default template in order to modify it to your liking. To do so, from the Advanced tab in Publish Settings, click the Export button and save the HTML file on your machine for editing. You will be prompted by Animate CC to give this file a name and location on your hard drive.

 

figure4

Figure 4. Exporting the Default Template file from the Advanced Publish Settings.

 

With the default template exported, you will now be able to open it up in Adobe Dreamweaver, Brackets, or any text editor of your choosing to customize the HTML, JavaScript, and CSS contained within. Perhaps you want to center your HTML5 Canvas content or add other elements like headers and descriptive text. This is all possible using Templates.

 

Editing the Template

Now that we have our Template file open within an editor, we can make whatever modifications we wish. In this example, I’ve styled the Body element to inherit the Stage background color as defined in our Animate project. I’ve also gone ahead and given some margin to the document, and have centered the Canvas element. That should make things a bit more balanced and lively!

 

figure5

Figure 5. Editing the Template HTML file in Brackets.

 

One thing to make note of before we move on, is the availability of special tokens with the HTML Template which ca be used when customizing. For instance, tokens such as $BG, $WT, and $HT can be used in conjunction with custom logic and elements to adjust for sizing and background colors within your Template.

Here is a short list detailing some of these tokens, and what they represent:

$CANVAS_ID                    The ID of the Canvas element within your HTML document.

$TITLE                                 The title of your project document.

$BG                                       The background color of the Stage defined within the FLA.

$WT                                       The width of the Stage defined within the FLA.

$HT                                       The height of the Stage defined within the FLA.

These tokens are available for use within any Template and will be replaced by their appropriate values upon publication. Other tokens exist as well, and can be explored within the exported HTML Template file.

 

Using Ad Network Code within a Template

In this example, we’ve created a very visual Template in order to more easily express what can be achieved through this mechanism. However, we can also include non-visual elements within a Template as often required by various ad distribution networks.

Here, for example, is a bit of HTML to include in the HEAD of your Template in order to conform to DoubleClick ad campaign requirements.

<meta name=”ad.size” content=”width=300,height=250″>

<script type=”text/javascript”>

var clickTag = “http://www.google.com”;

</script>

In the above code, we set the ad size though a META tag, and then expose a ClickTag variable for use within our Animate CC project. Within the actual Animate content, we can respond to user interaction by invoking the following:

window.open(window.clickTag);

This will allow the use of ClickTag events within out HTML5 Canvas project easily through the use of Animate CC Templates! The same sort of functionality can be enabled for a variety of ad distribution networks by creating a Template for each one.

 

Importing the Custom Template

When you are finished editing, save your HTML and return to Animate CC and the Advanced Publish Settings. Simply click the Import New… button and locate the edited HTML file to use it within your project. The selected template is now clearly indicated within the dialog.

 

figure6

Figure 6. Importing the custom Template file.

 

Now, whenever you test or publish your HTML5 Canvas document, it will employ your custom Template in place of the default. If at any time you wish to use the default Template again, simply click the Use Default button.

 

Publish Profiles

What if you have a number of Templates which you wish to switch between when publishing your content? It would be a pain to have to import Template files every time you need to switch. This is where Publish Profiles come into play.

To establish the Template just created as part of a Profile, you can click the gear icon and choose to Create profile.

 

figure7

Figure 7. Creating a custom Profile.

 

A small dialog will appear, allowing you to provide a name for this profile. In this manner, you can define any number of Profiles in your document and easily switch between them.

 

figure8

Figure 8. Naming the new Profile.

 

With a custom Profile defined in the project, you can now switch between that and the default with ease by simply choosing it by name from the dropdown. Note as well that these can be exported and imported to share between projects!

 

Employing Templates by Swapping Profiles

Templates can be automatically applied to your content prior to publication by assigning a specific Template to a Profile, and then switching to whichever Profile you want to use. This action will employ the specific Template applied within that Profile to the document being published.

For the last part of this article, I’ll go ahead and switch my Publish Profile to new newly created “Center Content + BGProfile by selecting it from the Profile dropdown in the Advanced tab of our Publish Settings dialog.

 

figure9

Figure 9. Switching Publish Profiles.

 

Clicking the OK button within our Publish Settings will apply the selected Profile and return us to the project document. Notice that the Properties Panel now reflects the selected Profile and no longer the default.

 

figure10

Figure 10. Selected Profile is indicated in the Properties Panel.

 

From here, we can once again test the project in the web browser by choosing Control > Test. The compiled HTML5 Canvas project will appear in a new browser window and the changes will become obvious with the entire background inheriting the Stage color chosen in Animate CC and the content itself perfectly centered – much nicer!

 

figure11

Figure 11. Published content using the custom Template and Profile

 

To return to the Default Profile or to manage and select other Publish Profiles, simply return to the Publish Settings dialog.

 

Jul 14, 2015/ActionScript, General, HTML5/

Converting your Flash Ads to HTML5 Canvas

The HTML5 Canvas document type and the associated design and performance capabilities in Flash Professional CC helps you create performance-optimized HTML5 creatives with ease. You can obviously create new ads targeting the HTML5 platform using Flash Professional CC, but you may also have have some existing Flash ads that you want to convert to HTML5 Canvas for targeting them for multiple platforms, especially mobile devices.  Here is how you do it:

  1. Convert your ActionScript document to HTML5 Canvas document using the document type converter.
  2. Replace the ActionScript code commented out as reference in the actions panel with their HTML5 Canvas equivalents. You can use the HTML5 Canvas code snippets panel (Window > Code Snippets) in Flash CC 2015 to get started.

Now, let’s see this in action.  We are going to convert a Flash ad to HTML5 Canvas.

Here is the ActionScript example:

Get Adobe Flash player





The converted HTML5 Canvas file should look like this:


Converting an ActionScript document and assets to HTML5 Canvas

  1. Download the BannerNewFeatures_AS3.zip file, extract the files, and open the BannerNewFeatures_AS3.fla file. You can preview the contents by opening BannerNewFeatures_AS3.swf.
  2. Click Commands > Convert to other document formats to convert the document to HTML5 Canvas document.
    Convert-menu-option
  3. In the Document Type Converter dialog box, select HTML5 Canvas and click Browse to select a location to save the converted FLA.
    Doctype-converter
  4. Click OK. The ad has now been converted in to HTML5 Canvas. Open the .html file in the output directory you specified in the previous step to check the converted output. You can see that all your art assets have been converted in to HTML5 Canvas. However, the ad runs in a continuous loop.  This change happened because we do not automatically convert the ActionScript code to the equivalent JavaScript code.

Note: Flash Professional does not auto-convert any ActionScript code to JavaScript code because there is no foolproof way to get it completely right. However, our HTML5 Canvas (CreateJS) JavaScript APIs mimic ActionScript code fairly closely. We also have some built-in Code Snippets in Flash CC to help you get started with some commonly used actions.

Converting ActionScript code to JavaScript in your HTML5 Canvas document

  1. Click Window > Actions to open the Actions panel. All your ActionScript code in FrameScript are displayed as commented out to help you convert them to HTML5 Canvas.

    ActionScript code commented out

    ActionScript code commented out

  2. In the Actions panel, click the ActionScript code that you want to replace and type in the JavaScript equivalent (if an equivalent code snippet is available in the the HTML5 Canvas section of the Code Snippets panel, you can just double-click on it) For example, the following image shows that the stop () ; function that is commented out in ActionScript has been replaced with its HTML5 equivalent, this.stop () ;
    Replace-code
  3. Press Shift+Alt+F12 to publish and check your output.
  4. To see how all the ActionScript code in the example document were converted in to HTML5 Canvas, download BannerNewFeatures_Canvas.zip and open the BannerNewFeatures_Canvas.fla file. To view the final output in HTML5, download Published-Banner-HTML5.zip. and open the BannerNewFeatures_Canvas.html file.

Codes for commonly used actions

The following are some of the commonly used ActionScript codes and their equivalent JavaScript codes:

  • Symbol Instances are referenced as this.instanceName instead of directly using the instanceName:
    ActionScript HTML5
    mySymbol.x = 100;
    mySymbol.visible=true;
    this.mySymbol.x = 100;
    this.mySymbol.visible=true;

     

  • Variable types and function return types should not be specified in JS:
    ActionScript HTML5
    var myVariable:String
    var myVariable;
    function onClick (event:MouseEvent) :void {
    //body
    
    }
    function onClick (event) {
    //body
    
    }

     

  • trace() is not supported and should be replaced by console.log() or alert():
    ActionScript HTML5
    trace(“Message to display”);
    console.log(“Message to display”);

     

  • Commonly used events in ActionScript and JavaScript:
    ActionScript HTML5
    MouseEvent.CLICK
    "click"
    MouseEvent.MOUSE_DOWN
    "mousedown"
    MouseEvent.MOUSE_UP
    "mouseup"
    MouseEvent.ENTER_FRAME
    "tick"
    MouseEvent.ADDED
    "added"

     

  • Commonly used timeline actions in ActionScript and JavaScript:
    ActionScript HTML5
    stop();
    this.stop();
    <InstanceName>.stop();
    this.<InstanceName>.stop();
    gotoAndStop(5);
    gotoAndStop("label");
    this.gotoAndStop(5);
    this.gotoAndStop("label");

    Refer the EaselJS documentation for more information about other events. Check out the mapping of ActionScript codes and their equivalent JavaScript codes for HTML5 Canvas platform for a comprehensive list of actions.

View and use JavaScript code snippets

  1. Click Window > Code Snippets.
    Code-Snippets-menu
  2. In the Code Snippets panel, expand HTML5 Canvas to see the HTML5 equivalents of your ActionScript codes under different categories.

    Code snippets panel

    Code snippets panel

Useful links

Sep 3, 2012/Animation, Flash Professional CS6, General, Toolkit for CreateJS/

Atari and Adobe Flash Professional

Important Note: Toolkit for CreateJS has now been replaced with HTML5.

It is highly unlikely that you are reading this blog post and have not played an Atari game ever before. For gamers, passionate or otherwise, casual or obsessive, skilled or talented, Atari games would have been one of the common starting points for developing gaming acumen. Do you know that Atari is taking its historic games to the mobile platform across multiple screens? Empowered by CreateJS libraries, Atari will deliver its games targeting the HTML5 platform to ensure compatibility across multiple mobile platforms and screens. For more information, watch this video.

The project involved creating multitudes of animated assets to create touch-friendly games with rich content. Yes, you guessed it right, Flash Professional CS6 along with the Toolkit for CreateJS extension and some custom JSFL was used to carry out this mammoth task of preparing assets. To know more about Toolkit for CreateJS, see this DevNet article. Also, visit gskinner.com to know more about Grant Skinner, creator of CreateJS and a prime contributor to the Atari HTML5 project.