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();
}
}
}