This is a quickly made tutorial about creating a simple menu-based HTML5 Canevas web site with Adobe Animate CC.
Learning goals
You can download an Animate CC design file (*.fla) after each important section in case you were unable to do it yourself or if you want to compare your solution with ours...
As of 2018, Adobe uses the same kind of user environment across most of its products. The Interface of Animate CC did not change much since Flash CS4, i.e. users familiar with Flash Professional versions of the last 10 years will not feel lost.
After launching the software:
Designer
layout. You can change that later though and even create your own favourite configuration. Read the Flash CS6 desktop tutorial for some information about docking panels. HTML 5 Canvas
. If you don't you will have to exit Animate CC and start over again.Most important interface elements
The most important interface elements with respect to our goal are:
Animate CC will create code for the HTML5 Canvas element, i.e. will not create code that interacts with the rest of the HTML page. Think of it as "Flash" made with JavaScript code. The "application" we will create will sit inside a <canvas> </canvas>
element of an HTML page. Depending on its purpose you will have to make it big enough. By default the canvas size is set to 550 x 400 px. We rather suggest using at least 800x600 pixels for creating interactive animations. Click somewhere in the workspace and adjust the size in the properties panel to the left.
You can make this size responsive, e.g. have it adapt to the size of a small HTML page.To so, open Publish settings -> Basic, see Make responsive
In order to create a menu-based side we will use the main timeline. Instead of using the frames for creating animations (as typical banner designers) do, we use the timeline to represent various contents (pages). Many game developers also use this strategy. You can ignore what that means precisely for now.
In the first steps, we will create various drawing layers in order to make editing more simple and more safe. Unlike other drawing programs (e.g. Illustrator or Inkscape), drawings can change over time in Animate CC. Each step in time is called a frame. Layers have at least one frame. Frames can be either empty (include nothing) or include something, e.g. drawings, JavaScript code, or so-called movie clips. Frames also can extend, i.e. the content of a drawing in frame 1 can still show in frame 25 if you extend it.
Each "page" will have the same several layers. These will include:
Global menu
with buttonsActions
layer that includes the menu codeBackgrounds
layer with some (optional) drawing objectsAnimations
layer that includes so-called movie clips (animation objects)Foregrounds
layer with some (optional) drawing objects (animations objects will run behind these)Please create five layers now (you always can add/remove or change these.
new layer
button (bottom left or the layer section). Do that five times.Lock all layers by clicking on the lock symbol.
As you can see, next to the layer names you can make visible/invisible, lock/unlock, draw everything/just the outlines. If Animate CC doesn't let you draw, unlock. If it does not show fills, click on the outline square, etc.
Since we plan to put different contents in each frame, we now must create blank keyf rames for the three layers that will be different, i.e. foregrounds, animations and backgrounds.
For each of these layers:
The result after doing this for the Animations layer should look like this, i.e. you should see five little circles
You are done when each frame of these three layers (Foregrounds, Animations and Backgrounds) includes a empty little circle.
Contents of these layers should be identical in all pages. We therefore just extend frame 1:
Now if you want to "see" something in the workspace.
T
(text) tool in the drawing panel to the left, e.g. menu.The result should look like the following screenshot. As you can see, there is a black dot in frame 1 of the Global menu layer. It tells that there is some content inside, e.g. the word "menu" in our case.
Finally, also extend the Actions layer
Source code (in case you missed something):
Creating a button is fairly simple, since as in HTML (and Flash too) anything can be a button. However, since a button should usually include some animation - i.e. the user should notice when he or she moves the cursor over a button or presses down - there will be some extra work to do.
Unfortunately, modern editions of Animate CC do not include pre-built buttons. You can buy some, copy from Flash CS6 or create your own. Let's create a simple model. We show below how to do this step by step.
Step 1: Draw a simple shape representing the button
Step 2: Transform the rectangle into a button symbol
F8
or right click and select Convert to Symbol
You now should see a popup panel called Convert to Symbol.
You now will see a so-called Symbol in the library panel to the right. Drag the symbol from the library to the scene. You will find a new instance. Notice, that you could delete all instances (drawings in the workspace), but the symbol will survive in the library.
The goal now is to create a moderately good looking (but working) button, as you could see in this HTML page.
You will first learn how to edit a Symbol. A symbol represents a class, i.e. a kind of blueprint that you could reuse several times. A Button symbol
is a special kind of class that allows creating any sort of animated button. To edit a symbol, double click on the symbol in the library panel. You also could double click on an instance in the workspace, but then you also will see the other objects in the workspace which might be confusing.
Now, do double click on the symbol in the library that we called "Button menu". You are now editing just a symbol, i.e. a class. As you can notice, the workspace looks differently, i.e. you only see a drawing of a rectangle. Make very sure to remember that you can edit things at various levels, i.e. the main scene (also called main timeline) or various things like buttons or animation clips that you will create. These classes themselves can contain other objects. Beginners are very often confused about this and do not pay attention to what they really edit.
A button symbol is an Animate CC class that makes use of 4 already defined animation frames. You cannot change this logic. The four different frames are used to define how a button should display depending on the user action.
Let's now add some simple graphics to these four frames:
You also might extend the graphic to all frames, i.e. the text will appear in all three states (up, over and down).
Add some highlighting hints
Buttons that you can find online are of various complexity. Most have several layers and include several graphic objects. Layers contain drawings for these four button frames. The Flash engine will then select the appropriate frame for display according to user action (mouse over, mouse down, etc.).
With the 3rd frame selected, you now should see something like this:
Let us test this button now in the HTML browser.
Control -> Test Movie -> In Browser
Source code that you can copy, if you are in a hurry.
We could reuse five times the same button symbol for our application. However, the text would be same for each. In order to get buttons with different texts we have to create five different symbols. To do so, we simple duplicate our button symbol. We then can adapt the text for each one.
Duplicate
You now should have six buttons (one spare)
The final result could be something like this:
Before we can test this structure we will have to tell HTML5 not to "play this animation". Remember that we use the frames of the main animation time line to represent pages.
F9
or Menu Window -> Actions
this.stop();
into the Actions popup windowNow let us see if the five buttons display in HTML
Control -> Test
For each Frame add some contents. Unless you already have a precise idea for the page contents you plan to create, we suggest just adding a little "doodle" that you later can remove.
Repeat for all five frames
The goal now is to create a working navigation framework:
You now can profit from your JavaScript coding skills or else learn some JavaScript. Our goal is to display a given frame after a user clicks on a given button. E.g., when the user clicks on the Page 3 button, we should see Page 3 (i.e. contents of frame 3). Let us walk through the steps:
(1) Give an instance name to each button
This is like providing an HTML element with an id attribute.
Repeat that for each menu button, until you got a list of buttons from btn1 to btn5.
(2) Create event handlers for each button plus a navigation function
Window -> Code snippets
. We suggest docking this panel next to the library.The Action (programming) window will pop up and you will get some code that you only need to change a little bit, e.g. adjust the frame number where it should navigate. For example, in the following code you only need to change the second last line:
this.gotoAndStop(0); // as opposed to gotoAndStop(5)
.
Warning: In JavaScript, counting starts at 0 meaning that frame #1 in Animate CC will be frame #0 in JavaScript. This is a bit confusing.
Below is the kind of code that Code Snippets will produce:
/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
2.Frame numbers in EaselJS start at 0 instead of 1
*/
this.btn1.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));
function fl_ClickToGoToAndStopAtFrame()
{
this.gotoAndStop(5);
}
Do not repeat this mindlessly. Each time you click on a code snippet it will be added to the code. Make sure to remove code that you do not want. Instead of selecting each button and using code snippets, you also could just copy paste code for the previous button and adjust. Each button must have a different event handler and each event handler must specify a different function.
Alternatively, if your buttons are named btn1 ... btn5 you can copy/paste the following code:
// Prevent HTML5 from playing the scene
this.stop();
this.btn1.addEventListener("click", move1.bind(this));
this.btn2.addEventListener("click", move2.bind(this));
this.btn3.addEventListener("click", move3.bind(this));
this.btn4.addEventListener("click", move4.bind(this));
this.btn5.addEventListener("click", move5.bind(this));
function move1() { this.gotoAndStop(0); }
function move2() { this.gotoAndStop(1); }
function move3() { this.gotoAndStop(2); }
function move4() { this.gotoAndStop(3); }
function move5() { this.gotoAndStop(4); }
One could write some more elegant code:
(3) Test navigation
Now let us see if the five buttons will do HTML navigation
Control -> Test
Source code in case you did not manage:
Let us assume that you want to get rid of frame #3. Select frame 3 in all all layers, right click and remove frames. This works fine, but will mess up your nice JavaScript code, since frame 4 will become frame 3, etc.
To avoid that, you could give a name to the frames used in navigation. In any layer that has a complete set of keyframes, e.g. the Actions Layer, do the following:
You now can change the JavaScript code like this, i.e. used quoted frame names instead of frame numbers:
this.btn1.addEventListener("click", move1.bind(this));
this.btn2.addEventListener("click", move2.bind(this));
this.btn3.addEventListener("click", move3.bind(this));
this.btn4.addEventListener("click", move4.bind(this));
this.btn5.addEventListener("click", move5.bind(this));
function move1() { this.gotoAndStop("menu"); }
function move2() { this.gotoAndStop("p1"); }
function move3() { this.gotoAndStop("p2"); }
function move4() { this.gotoAndStop("p3"); }
function move5() { this.gotoAndStop("p4"); }
You now can add contents to each "page". We suggest using one or all of the three Foregrounds, Animations and Background layers for this.
If you want to remain at this level, you simply could add some pictures or movies (using menu File->Import) and some text. However, the initial plan is to add some animations.
Per definition, the Animate CC scene - i.e. your whole Animate CC file - is a movie clip. However, since we used the main timeline to create "pages" we now will have to use so-called embedded movie clips to create various animations. You can use any Animate CC tutorial to learn more about Animations, but remember not to use the main timeline.
Flash includes several types of animations, some of which were explained in the Flash animation overview made for CS6. Animate CC adds the Camera tool.
In this tutorial we will introduce basic motion animation, called Motion tweening in the old Flash terminology. Motion animation includes:
The word "tweening" (a short for in between-ing) explains how it works. As a designer you only to specify a few so-called keyframes that defined changed properties (e.g. a new position or a new rotation angle). The computer will then calculate a smooth transition between these keyframes. As a minimum, you need a start and an end keyframe. This principle is no different from other animation frameworks, e.g. CSS3 animation or SVG animation.
CTRL-F8
or Menu Insert -> New Symbol
Movie Clip
Draw a rectangle for reference:
Repair position and size of the new rectangle:
Remember that this rectangle will just give some guidance for creating an animation. You can remove it later ...
Draw a round orange ball:
Turn the graphic into a Symbol since only symbols can be motion animated.
F8
or right-clickExtend the drawing in the background layer (must be done before creating the motion tween in Animate CC 2015!)
Create the motion animation
Create Motion Tween
As result you will see a new layer in the timeline of this object that includes 24 (or more) blue frames
Now make sure that the red play head (on top of the timeline) is still in position 24
You now see a motion animation line:
The result should more or less look like this:
So far, our new animation is just a symbol in the library. To use it, you will have to drag onto the scene:
Enjoy:
By definition any animation will play as soon as the movie clip is shown. E.g. in our example, if you move from the "menu" frame to "page 1" frame you will see the rising sun animation repeat itself forever.
To stop an animation after it ran once, do the following:
this.stop();
Running example and source code:
In general - but not always - it is better to leave control to the user, i.e. allow the user to stop and start an animation.
We inserted in page 3 a new Rising Moon animation that is a bit less ugly than the one on page 1. It works with the same principles as the simple animation we introduced above.
Pale Moon clip
. It includes a background, a foreground, a button and "moving moon" clipsMoon_animation
clipIn principle you just could use the following JavaScript code to start/stop an animation:
this.anim.play()
this.anim.stop()
Or, alternatively:
this.anim.paused = false; // or true
In practice, stopping an animation before it starts does not seem to work, since the animation starts moving before JavaScript executes the code. This wasn't the case in ActionScript. There are two workarounds:
setTimeout(stopit,0);
function stopit(){
exportRoot.myPaleMoon.moon_anim.paused = true;
}
Notice: If you wanted to stop the Sun rising animation, you would refer to it with something like:
exportRoot.mySunrise.paused = true;
The following code allows to stop/start three different animations. After the user clicks on the button, the state of animation is reversed, i.e. the paused
property is either true or false. This works as expected (unlike stopping an animation before it can start).
this.btn1.addEventListener("click", go.bind(this));
function go(ev) {
console.log("go: Mouse clicked"); // test if the click worked-:
// reverse animation states
// paused is set to its opposite (either true or false)
this.moon_anim.paused = ! this.moon_anim.paused;
this.moon_anim2.paused = ! this.moon_anim2.paused;
this.moon_anim3.paused = ! this.moon_anim3.paused;
console.log("this.moon_anim.paused=" + this.moon_anim.paused);
}
Source code and running example (look at frame 3)
Instead of using buttons to control stop and start, you also could simply use the objects themselves as buttons. This is demonstrated with the parrot animation on page 4.
JavaScript code used is the following. Note that we also use a simpler way of defining event handlers using the on
method. This wasn't found in the Adobe documentation, but in the Easel.js documentation.
The three parrots are instances of the same clip called Parrot_Clip. Their names are Tom, Tim and Tibor (for a reason no one remembers).
setTimeout(stopit, 0);
function stopit() {
exportRoot.Tom.paused = true;
exportRoot.Tim.paused = true;
exportRoot.Tibor.paused = true;
}
// Method addEventListener + bind "sold" by Adobe.
// "this in the function will refer to the scene
// "this" est la scène, utile quand un seul bouton déclenche qc.
this.Tibor.addEventListener("click", startStop.bind(this));
function startStop(ev) {
console.log("Event=" + ev + ", target=" + ev.target);
this.Tibor.paused = !this.Tibor.paused;
}
// Method on
// "this" in the function will refer to the object that triggers the event.
this.Tim.on("click", startStopObj);
this.Tom.on("click", startStopObj);
function startStopObj(ev) {
// console.log("Event=" + ev + ", this=" + this);
this.paused = !this.paused;
}
The animations are simple motion tweens. Instead of moving like in the previous example, we just rotate parts of the parrots. The only noticeable point is that we moved the rotation point. This explained in some more details in some older Flash_object_transform_tutorial#Rotations Flash object transform tutorial. The interface for changing a rotation point is mostly the same in Animate CC.
Source code and example:
Drawing in Animate CC is similar to drawing in Flash. Until this section is updated see the old basic drawing and the advanced drawing list of tutorials in the old Flash tutorials.