Tuesday, December 13, 2011

Adobe Edge animation controlled by the scrollbar! its easy and fun.

How to make your animation controlled by the scrollbar in Adobe Edge Preview 3:

Adobe edge is a great HTML 5 editing tool, and with a few tweaks I think it will end up being the best html5/javascript/jquery tool on the market for professionals looking to create highly interactive non-flash interactive animations. I've been a flash programmer for 14 years now, and I actually enjoy working on the timeline so Adobe Edge is a lot more creatively satisfying than working with eclipse to make "interactive art", at least for me.

In this example I made an animation in Adobe Edge that the user "Scrubs through" with the scrollbar instead of it just playing automatically as is the default for Adobe Edge. I think its a good way to introduce the lay person to the concept of scrubbing a playhead through time, and would make a neat "popup book" for kids with a simple approach like this as it is a different use of a familiar UI element, the scrollbar. As a flash user, I've always hated scrollbars because I think information should be presented in one place using time/animation rather than making the user scroll through it, but I have built them from scratch in flash AS3 (see previous post) and this makes for an interesting continued experiment with the things.

Example (drag the scrollbar to advance the animation)
http://www.northeastmagic.com/adobeEdge/scrollbar_scrubber/test7.html

Allowing the user to scrub through your html5 animation created in Adobe Edge allows them to have a "popup book" feel of control over your work, making it interesting to play with. Scrolling is a familiar control interface but using it as a playhead scrubber opens up a new realm of possibility to the user unfamiliar with animation development. Note: the animation has to be wider than the users's viewport or this wont work - so you designers with huge monitors will have to shrink the window down a bit...

From an animator perspective, try to make your animation in segments that can be easily divided into the physical width of the artwork (or height if you are vertically scrolling). So for example a 4 second animation could be 2000px wide, and you basically do 1 scene inside 500px, bearing in mind that animation occurring in the left side will not be visible as the user scrolls through the piece. (Per second you allow 500px for that "second's" scene. Its a weird way to think about animation but hopefully thinking of it this way will help.

As of writing this article, Adobe Edge preview 3 is fairly buggy, for example trying to work with objects that go beyond the right side of the viewable area is problematic since the selection tools basically become unavailable when you scroll. My workaround for that was to do the animation in the viewable area first, then move the playback head to 0:00, then translate the x of the animated objects to the far right as far as I could without losing selection. Interestingly when you translate an object while the playhead is at 0, it affects all keyframes of the object, so this seemed to be a workaround for now. Hopefully adobe will address this, as well as adding the ability to set the width/height with percentages instead of px, and individually control the overflow handling of the vertical and horizontal scrollbars.

1. add a trigger to the beginning of the animaton this.stop();




2. add a "scroll" event to the stage top right. paste the following code in there

// insert code for scroll event here
var myCalc=this.element.scrollLeft/(this.element.scrollWidth-this.element.clientWidth);
this.stop(myCalc*this.getDuration());




3. make the animation etc. work at the full width. Make a note of the stage width you picked (2000px etc.) top left.




4. when finished save, leave edge and look in the files it created.

5. Open the one called "MYFILENAME_edge.js" in dreamweaver

6. do a find for "2000px" or whatever the width was that you picked. .... replace width value with "100%"

something like : id: "eid1", tween: [ "style", "${_stage}", "width", '100%',

is the important one. There should only be 1 _stage line. If there is more you've tweened the stage and you should remove them.

7. if you are scrolling horizontally you'll need to hide the vertical scroller like this:


one of the objects should have a stage object, add the overflow-x and overflow-y appropriately:

"${_stage}": [
["color", "background-color", 'rgba(12,12,13,1.00)'],
["style", "width", '500px'],
["style", "height", '400px'],
["style", "overflow-y", 'hidden'],
["style", "overflow-x", 'auto']
],

REALLY IMPORTANT, dont forget to make sure there are commas between each line and NOT one on the end of the last line

if you want to vertical scroll, use overflow-y auto and overflow-x hidden, and set the height to 100%. You can also set both height and width to 100% to push the scrollbar to the bottom of the frame.

I still think flash is far more advanced of a tool for animation and rich internet applications, but given the landscape of politics these days with iOS refusing to allow flash for their own inane reasons, we can learn to "build a ferrari with toothpicks" and use HTML 5 / javascript to appease the ignorant "flash haters" out there.

About the author:
Ryan Cameron is CTO of SweetRush inc., a SanFrancisco based e-learning and interactive technology development company. Ryan works virtually and lives in Nova Scotia, Canada.

11 comments:

  1. an addendum to this one. Apparently there is a limit of 4000 pixels ( 4000px ) on the iOS version 4.3, perhaps lower. I dont have any official documentation from Apple but I really would like to point out that Apple has abysmal support for JQuery/javascript/html 5 considering if it wasnt for Apple, we could build all this stuff in flash and ignore html 5. In spite of all Apple's glorious interfaces and hardware, they appear to be clueless on rich media as is clear to any artist who's tried to use XCode or their technology to do "cool" things with interactive rich media. I wish they'd embrace flash and let the professionals do their work, and just focus on making really beautiful hardware and ui.

    ReplyDelete
  2. Thanks for the share. Keep posting such kind of information on your blog. I bookmarked it for continuous visit.
    flash to html5 converter

    ReplyDelete
  3. Hi, I´ve try to do this sample vertical scroll, but when I set the height to 100%, the Stage disappear. Can you help me?

    ReplyDelete
  4. I am assuming that when you created this you did not have to manipulate the _edgeActions.js file to do this:
    2. add a "scroll" event to the stage top right. paste the following code in there

    // insert code for scroll event here
    var myCalc=this.element.scrollLeft/(this.element.scrollWidth-this.element.clientWidth);
    this.stop(myCalc*this.getDuration());

    In current Edge you do because the script it generates targets the document and not the stage... Also they have changed some of the js files so your script does not work at all.

    ReplyDelete
  5. Hi. This technique doesn't seem to work in Edge 6 as the js files are different to how you describe them. Can you suggest a workaround, or another way of doing this in Edge 6? I'd really love to get this functionality!

    ReplyDelete
  6. It will nice if the author can update this solution to for adobe edge animate 7 for both horizontal and vertical. Wonderful solution

    ReplyDelete
  7. The fixed calculation for Edge 7 is:

    var myCalc=sym.element.scrollLeft()/(sym.element[0].scrollWidth-sym.element[0].clientWidth);

    ReplyDelete
    Replies
    1. Is there any way to not scroll the page/contnet vertically and just effect the animation timeline? The problem is, the page scrolls if the content is really long (large image) and I want to move through the large image by animating the timeline and not scrolling it... basically so I can move diaganal, up, down, left and right.

      Delete
  8. I am no longer working on this project and have subsequently returned to flash. HTML5/JS simply evolves too slowly and is inconsistent across browsers making it incredibly frustrating to use. For PC based projects I've concluded flash is the best technology for any kind of interactivity beyond the most basic point and click websites, and on mobile it seems the app store (which is still accessible with flash) is the way to go, at least until full operating systems are supported on tablets and smartphones. (Surface with Windows 8 next year will be the first of many I surmise)

    ReplyDelete
  9. i need adobe edge preview 3, please show me the link... because i have tried your script into newer of adobe edge animate, it can't work anymore! or could u give me a solution for using the new one of edge? i wanna make the same apps like u made before using adobe edge preview 3

    thanks in advance..

    ReplyDelete
  10. Hey this is a fantastic post and just what I'm looking for. I'm making an interactive comic book and while planning the project, the term pop up book definitively came to mind. I would personally love it if you made this tutorial into a video tutorial on youtube. Thanks for the post, Edge right now is a bit more stable from the preview release.

    ReplyDelete