Hi rhernando, hi bassta
thanks for answering. I learned about literal arrays and the links to javascript sites were extremely helpful.
And:
I tried the proposal with $("<div class='blob' />"), but I couldn't get it to work.
here my codepen:
http://codepen.io/codepenmicha/pen/vnhuF
It seems this it not what you mean.
sorry about making it big, but I'm faszinated of the idea of multiple objects and I like to show you the actionscript from Carl first (just for orientation) and then my attempt to get it work with javascript and tweenMax only.
here is the actionscript (from: http://hub.tutsplus.com/tutorials/timelinelite-ultimate-starter-guide-advanced-sequencing--active-10331):
package {
import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.easing.*;
//import com.greensock.TweenAlign;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.controls.Button;
import fl.controls.Slider;
import fl.events.SliderEvent;
public class MultipleNestedTimelines extends MovieClip {
public var tl:TimelineMax;
public var blobTweens:Array;
//stage instances
public var slider:Slider;
public var restart_btn:Button;
public var meet_mc:MovieClip;
public var the_mc:MovieClip;
public var blobs_mc:MovieClip;
public function MultipleNestedTimelines():void {
if (stage) {
init();
}
else {
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
private function init(e:Event = null):void {
//set up nav events
slider.addEventListener(SliderEvent.THUMB_DRAG, sliderChange);
restart_btn.addEventListener(MouseEvent.CLICK, restart);
blobTweens = [];
//create blobs and their respective timeline animations
createBlobs();
createMasterTimeline();
}
private function createBlobs():void {
for (var i:int = 0; i < 30; i++) {
var blob:Blob = new Blob();
blob.y = 475;
addChild(blob);
var blobAni:TimelineLite = new TimelineLite();
blobAni.insertMultiple([
TweenLite.to( blob, 2, {x:680, ease:Linear.easeNone}),
TweenLite.to( blob, .5, {y:Math.random() * 200}),
TweenLite.to( blob, .9, {rotation:360, delay:.1}),
TweenMax.to( blob, .5, {y:230, ease:Quad.easeIn, delay:.5})
]);
blobTweens.push(blobAni);
}
}
private function createMasterTimeline():void {
tl = new TimelineMax({onUpdate:trackProgress});
//pass an array of clips to allFrom();
tl.insertMultiple( TweenMax.allFrom( [meet_mc, the_mc, blobs_mc], .5, {scaleX:0, scaleY:0, ease:Back.easeOut} ), 0, TweenAlign.NORMAL, .3);
//blobTweens array was populated with TimelineLite's in createBlobs()
tl.appendMultiple(blobTweens, 0, TweenAlign.NORMAL, .4);
}
//slider and nav controls
private function trackProgress():void {
slider.value = tl.currentProgress * 100;
}
private function sliderChange(e:SliderEvent):void {
tl.pause();
tl.currentProgress = slider.value * .01;
}
private function restart(e:MouseEvent):void {
tl.restart();
}
}
}
and here is my attempt in codepen:
http://codepen.io/codepenmicha/pen/oAgcD
$(window).load(function(){
var tl = new TimelineMax;// ({onUpdate:myupdateHandler});
var blobTweens = [];//array literal
createBlobs();
createMasterTimeline();
function createBlobs() {
for (var i=0; i<4; i++){
var blob = $("#blob");
//var blob = $("<div class='blob' />");// doesn't work
//var blob = $(".blob");
var blobAni = new TimelineLite();
blobAni.insertMultiple([
TweenLite.to(blob, 2, {x:480}),
TweenLite.to(blob, 0.5, {y:-250}),
TweenLite.to(blob, 0.5, {rotation:350, delay:.1}),
TweenLite.to(blob, 0.5, {y:-140, delay:0.5})
]);
blobTweens.push(blobAni);
}
}
function createMasterTimeline() {
tl = new TimelineMax();
tl.appendMultiple(blobTweens, 0, "normal", .5);
//tl.add(blobTweens, 0, "normal", .5);
}
});
How do I check if blobTweens.push(blobAni); works?
and how do I fill the MasterTimeline with the looped timeline so that I get multiple instances of blob?
I hope this is interesting
thank you for advices
Michael