Converting timeline tween to as3
Hi,
I found this tutorial on creating a sticker and made my own, but because its a timeline tween it really seems to slow down my entire site. I attempted to convert it to as3 using TweenMax, but can't seem to get the numbers right--it should play on(stick) and unstick(reverse animation).
Here is some of the TweenMax code, which as you can see is incredibly confusing and too hard coded(ie, I would like the x and y positions to be more relative):
Code:
myTween= new TweenMax(maskf,.61,{x:38,y:38,onComplete:addPdfListeners});
myTweenBack= new TweenMax(maskb,.212,{x:-43.5,y:-6.8,onComplete:function(){TweenMax.to(maskb, .1, {x:36.3,y:11.1,onComplete:function(){TweenMax.to(maskb, .29, {x:70,y:-7})}})}});
myTweenBackSticker= new TweenMax(stickerback,.17,{x:9.2,y:15.9,onComplete:function(){TweenMax.to(stickerback, .05, {x:34.7,y:36.56,onComplete:function(){TweenMax.to(stickerback, .098, {x:93.5,y:77.76,onComplete:function(){TweenMax.to(stickerback, .293, {x:117,y:150.76})}})}})}});
I've attached the fla.
Any help would be greatly appreciated...
Thanks,
---Yvette
2nd attempt to post files
ok--attached is the fla and here is the as file:
Code:
package
{
import flash.display.*;
import flash.events.*;
import com.greensock.TweenMax;
import com.greensock.easing.*;
import com.greensock.plugins.*;
public class Sticker extends MovieClip
{
public var pdf:MovieClip;
public function Sticker()
{
if (stage)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE,init);
}
}
private function init(e:Event=null):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
/*stage.align = StageAlign.TOP_LEFT;*/
stage.scaleMode = StageScaleMode.SHOW_ALL;
handBackAdd();
}
private function handBackAdd():void
{
pdf.maskb.x=-190;
pdf.maskb.y=-283;
myTween = new TweenMax(pdf.maskf,.61,{x:145.75,y:-349.95,onComplete:addPdfListeners});
myTweenBack = new TweenMax(pdf.maskb,.22,{x:-140,y:-55,onComplete:function(){TweenMax.to(pdf.maskb, .098, {x:-80,y:21,onComplete:function(){TweenMax.to(pdf.maskb, .29, {x:120,y:175})}})}});
myTweenBackSticker= new TweenMax(pdf.stickerback,.17,{x:314.95,y:21.4,onComplete:function(){TweenMax.to(pdf.stickerback, .05, {x:424.5,y:109.3,onComplete:function(){TweenMax.to(pdf.stickerback, .098, {x:538.25,y:284.55,onComplete:function(){TweenMax.to(pdf.stickerback, .293, {x:902.55,y:637.85})}})}})}});
}
private function addPdfListeners():void
{
trace(pdf.maskb.x,pdf.maskb.y,pdf.stickerback.x,pdf.stickerback.y);
pdf.buttonMode = true;
pdf.addEventListener(MouseEvent.ROLL_OVER,playOverPdf);
pdf.addEventListener(MouseEvent.ROLL_OUT,playOutPdf);
pdf.addEventListener(MouseEvent.CLICK,downloadPdf);
}
private function removePdfListeners():void
{
pdf.buttonMode = false;
myTween.reverse();
pdf.gotoAndPlay("wipeoff");
pdf.removeEventListener(MouseEvent.ROLL_OVER,playOverPdf);
pdf.removeEventListener(MouseEvent.ROLL_OUT,playOutPdf);
pdf.removeEventListener(MouseEvent.CLICK,downloadPdf);
}
function playOverPdf(evt:MouseEvent):void
{
var et:MovieClip = evt.currentTarget as MovieClip;
TweenMax.to(et, 1, {scaleX:.335, scaleY:.335, ease:Back.easeOut,onComplete:function(){TweenMax.to(et, .315, {scaleX:1, scaleY:1, ease:Back.easeOut})}});
tt = new Tooltip(this.stage,0xFFFFFF);
addChild(tt);
tt.showBottom("Download pdf");
}
function playOutPdf(evt:MouseEvent):void
{
removeChild(tt);
var et:MovieClip = evt.currentTarget as MovieClip;
TweenMax.to(et, 1, {scaleX:.315, scaleY:.315, ease:Back.easeOut});
}
private function downloadPdf(evt:MouseEvent):void
{
removeChild(tt);
removeChild(pdf);
}
}
}
Thanks,
----Yvette