How do I create a timeline based animation using createJS code in Adobe AnimateCC? - createjs

I want to tween using code inside Adobe AnimateCC by using createJS, but when I try and chain them together/animate objects in a sequence, I am running into trouble as they both start at the same time (rather than the square moving then the Circle moving), here is the open AnimateCC file: http://spectrumcreative.co.nz/stackOverflow/animateWithCode.fla and here is my code:
var targetSquare = this.square;
var tweenSquare = createjs.Tween.get(targetSquare, {loop: false})
.to({x: 300}, 1500, createjs.Ease.bounceOut)
var targetCircle = this.circle;
var tweenCircle = createjs.Tween.get(targetCircle, {loop: false})
.to({x: 300}, 1500, createjs.Ease.bounceOut)

The easiest way is to use wait()
I just made animationTime variable for reuse, you can set any amount of time in wait()
var animationTime = 1500;
var targetSquare = this.square;
var tweenSquare = createjs.Tween.get(targetSquare, {loop: false}).to({x: 300}, animationTime, createjs.Ease.bounceOut)
var targetCircle = this.circle;
var tweenCircle = createjs.Tween.get(targetCircle, {loop: false}).wait(animationTime).to({x: 300}, animationTime, createjs.Ease.bounceOut);
This can be done also like this, so the second animation would start only after the first one is finished and call() will fire.
var animationTime = 1500;
var targetSquare = this.square;
var tweenSquare = createjs.Tween.get(targetSquare, {loop: false}).to({x: 300}, animationTime, createjs.Ease.bounceOut).call(function(){
var targetCircle = this.circle;
var tweenCircle = createjs.Tween.get(targetCircle, {loop: false}).to({x: 300}, animationTime, createjs.Ease.bounceOut);
});

Related

how to hide labels from Arcgisdynamic Layer javascriot/

I want to hide labels from Arcgisdynamic layer.
Below is the code,
var drawingOptions = new LayerDrawingOptions();
drawingOptions.showLabels = false;
var options = [];
options[0] = drawingOptions;
mylayer.setLayerDrawingOptions(options);
var sls = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, esri.Color([255, 255, 0]), 3);
drawingOptions.renderer = SimpleRenderer(sls);
When i add the above code my layer is not showing. I am using javascript 3.0 API

how to return shape from mouse event evt.currentTarget.children[0]

var stage, output;
function init() {
stage = new createjs.Stage("testCanvas");
// this lets our drag continue to track the mouse even when it leaves the canvas:
// play with commenting this out to see the difference.
stage.mouseMoveOutside = true;
var circle = new createjs.Shape();
circle.graphics.beginFill("red").drawRoundRect(0, 0, 100,20,10);
//console.log(circle.graphics.command.radius);
var label = new createjs.Text("drag me", "bold 14px Arial", "#FFFFFF");
label.textAlign = "center";
label.y = -7;
var dragger = new createjs.Container();
dragger.x = 50;
dragger.y = 10;
dragger.addChild(circle, label);
stage.addChild(dragger);
dragger.on("pressmove",function(evt) {
// currentTarget will be the container that the event listener was added to:
//evt.currentTarget.x = evt.stageX;
//evt.currentTarget.y = evt.stageY;
// make sure to redraw the stage to show the change:
//console.log(evt.currentTarget.children[0].graphics.command);
var newWidth= evt.stageX - evt.currentTarget.x;
console.log(evt.currentTarget.children[0].graphics);
if(newWidth<0)
newWidth = 0;
evt.currentTarget.children[0].graphics.command.w= newWidth;
evt.currentTarget.children[1].x= newWidth/2;
stage.update();
});
stage.update();
}
this code is working fine under http://www.createjs.com/demos
(i can reach this evt.currentTarget.children[0].graphics.command.w, because evt.currentTarget.children[0] returns shape)
but not on your own html. it is there any js i need to add in the heading?
Did you checked if "pressmove" trigger?
Maybe you should use this stage.enableMouseOver(20); to enable mouse events.

ActionScript 2 following a path

I am having a problem finding information on using actionscript 2 to move an object along a more complicated path. I have no issue if i need to tween in the x or y direction, or at the same time, but If i wanted an object to follow a curvy path could someone provide me sample code for a way to follow a motion guide or a curved path like a bezier?
here is my usual code:
Tween1();
function Tween1(){
setTimeout(theTween, 0);
function theTween(){
var myTween:Tween = new Tween(Object, "_x", Regular.easeOut, 0, 100, 1, true);
var myTween:Tween = new Tween(Object, "_y", Regular.easeOut, 0, 100, 1, true);
}
try this Animate along bezier curve
var circle:Shape = Shape(addChild(new Shape));
with(circle.graphics) beginFill(0x000000), drawCircle(0,0,5);
var bezierPoint:Point = new Point();
function bezier(a:Number, x1:Number, y1:Number, x2:Number, y2:Number, x3:Number, y3:Number):void {
var b:Number =1-a;
var pre1:Number=a*a;
var pre2:Number=2*a*b;
var pre3:Number=b*b;
bezierPoint.x = pre1*x1 + pre2*x2 + pre3*x3;
bezierPoint.y = pre1*y1 + pre2*y2 + pre3*y3;
}
var inc:Number = 0;
var theta:Number = 0;
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
graphics.clear();
graphics.lineStyle(0,0xFF0000);
graphics.moveTo(200,200);
graphics.curveTo(mouseX, mouseY, 400, 200);
inc += .03;
inc %= 1;
bezier(inc, 200, 200, mouseX, mouseY, 400, 200);
circle.x = bezierPoint.x;
circle.y = bezierPoint.y;
}

three js vertices does not update

I'm using three.js r67, and vertices does not seem to be updated.
I set geometry.dynamic = true, geometry.verticesNeedUpdate = true.
Circle is moving, but line is static....
Someone could help me?
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer();
var g = new THREE.CircleGeometry( 4, 16 );
var m = new THREE.MeshBasicMaterial({color: 0x114949});
var circle = new THREE.Mesh( g, m );
circle.position.x = 2;
circle.position.y = 2;
circle.position.z = -1;
scene.add( circle );
var material = new THREE.LineBasicMaterial({color: 0xDF4949, linewidth: 5});
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(0, 0, 0));
geometry.vertices.push(new THREE.Vector3(1, 1, 0));
geometry.verticesNeedUpdate = true;
geometry.dynamic = true;
var line = new THREE.Line(geometry, material);
scene.add(line);
var update = function() {
circle.position.x += 0.01;
line.geometry.vertices[0].x = circle.position.x;
};
var render = function() {
renderer.render(scene, camera);
};
var loop = function() {
update();
render();
requestAnimationFrame(loop, renderer.canvas);
};
loop();
Note: The legacy Geometry class has been replaced with the BufferGeometry class.
If you want to update the vertex positions of your BufferGeometry, you need to use a pattern like so:
mesh.geometry.attributes.position.array[ 0 ] += 0.01;
mesh.geometry.attributes.position.needsUpdate = true;
After rendering, you need to reset the needsUpdate flag to true every time the attribute values are changed.
three.js r.147

is it possible to to apply mouse/touch events to masks with EaselJs?

Is it possible to add mouse events to a shape mask? I have the mask working, and have animated it in other tests. But now I want to know if masks can be clicked and dragged.
You can see the example here: http://www.webnamehere.com/mask/mask.html
And although Easeljs never never seems to work in jsFiddle, you can also see the code here: http://jsfiddle.net/8kbu3/1/
var circle = new createjs.Shape();
var Galaxy;
$(document).ready(function() {
canvasWidth = "1024px";
canvasHeight = "768px";
stage = new createjs.Stage('demoCanvas');
createjs.Touch.enable(stage);
$("#demoCanvas").attr({width:canvasWidth, height:canvasHeight});
Galaxy = new Image();
Galaxy.src = "images/galaxy.jpg";
Galaxy.onload = handleImageLoad;
function handleImageLoad() {
GalaxyBitmap = new createjs.Bitmap(Galaxy);
GalaxyBitmap.x = 0;
GalaxyBitmap.y = 0;
containerGalaxy = new createjs.Container();
containerGalaxy.addChild(GalaxyBitmap);
containerGalaxy.x = 0;
containerGalaxy.y = 0;
circle = new createjs.Shape();
circle.graphics.beginFill('blue').drawCircle(80,80,50).endFill();
containerGalaxy.mask = circle;
stage.addChild(containerGalaxy);
stage.update();
}
circle.onClick = function(evt){
alert('what the F?');
}
circle.onPress = function(evt){
var offset = {x:circle.x-evt.stageX, y:circle.y-evt.stageY};
evt.onMouseMove = function(ev) {
circle.x = ev.stageX+offset.x;
circle.y = ev.stageY+offset.y;
console.log("circle X: " + circle.x + " | Y: " + circle.y);
stage.update();
}
}
Thanks guys
To receive an click-event you have to add the circle to the stage (stage.addChild(circle)) or to a child of the stage, even if it acts as a mask - in your case it might be better to take a transparent dummy-object as the click-listener.