PDA

View Full Version : Tween error



Criz
April 4th, 2008, 04:33 AM
So what I want is a picture that slides out to the right when I click on the grey frame.
Now it does go right but not with the desired easing. I canīt click it back as well which kind of frustrating. :-/

Iīve checked the linkage with the fla file and itīs fine. Same with the fla itself so there has to be a problem with the code somewhere. I think thereīs some problem with the handler like the tween motion just quit and jump to the end.

I appriciate your help / Criz


import se.criz.effects.Popout;
var popout:Popout = new Popout(slice);
package se.criz.effects {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

public class Popout {
private var _clip:MovieClip;
private var _startX:Number;
private var _endX:Number;
private var _easing:Function = Regular.easeInOut;
private var _duration:Number = 25;
private var twX:Tween;

public function Popout(clip:MovieClip) {
_clip = clip;
_startX = _clip.x;
_clip.gotoAndStop(2);
_endX = _clip.x;
_clip.gotoAndStop(1);
_clip.buttonMode = true;
_clip.addEventListener(MouseEvent.CLICK, popoutMe);
initClip();
}
private function initClip() {
_clip.x = _startX;
}
private function popoutMe(event:MouseEvent):void {
_clip.parent.addChild(_clip);
_clip.removeEventListener(MouseEvent.CLICK, popoutMe);
_clip.gotoAndStop(2);
twX = new Tween(_clip, "x", _easing, _startX, _endX, _duration, true);
function finishHandler(event:TweenEvent) {
twX.removeEventListener(TweenEvent.MOTION_FINISH, finishHandler);
_clip.addEventListener(MouseEvent.CLICK, popinMe);
}
}
function popinMe(event:MouseEvent):void {
_clip.parent.addChild(_clip);
_clip.removeEventListener(MouseEvent.CLICK, popinMe);
twX = new Tween(_clip, "x", _easing, _endX, _startX, _duration, true);
function finishHandler(event:TweenEvent) {
twX.removeEventListener(TweenEvent.MOTION_FINISH, finishHandler);
_clip.gotoAndStop(1);
initClip();
_clip.addEventListener(MouseEvent.CLICK, popoutMe);
}
}
public function set startX(theValue:Number) {
_startX = theValue;
initClip();
}
}
}

Felixz
April 4th, 2008, 10:53 AM
Maybe try to pull out those inner functions (they always give unexperienced user problems (including me))

Criz
April 8th, 2008, 02:53 AM
Seems like the problem orginated from the _clip.x variable. It just doesnīt take the desired x varible. I tried change it to a constant and the script worked. I think it has to do with that Iīve multiple objects within the movieclip.

example

_startX = _clip.x;

to


_startX = 0 ;