[Tweener] AS 3 If/Else issues with Tweener
Cedric Muller
flashcoder at benga.li
Tue Nov 11 09:00:53 PST 2008
Hi! Welcome to Tweener.
try this instead... off by head, I didn't test, I hope it is ok,
should be :)
blue.blue_BTN.addEventListener('mouseUp', moveButton);
function moveButton () {
Tweener.removeTweens(blue);
if (blue.x <= 166) {
Tweener.addTween(blue, {x:638, time:1})
} else if (blue.x >= 638) {
Tweener.addTween(blue, {x:166, time:1})
}
}
Please note that you can 'optimize' the blue.x <= 166 and blue.x >=
638 test like the following, for example:
this.currentBluePosition = 'left';
blue.x = 166;
blue.blue_BTN.addEventListener('mouseUp', moveButton);
function moveButton () {
Tweener.removeTweens(blue);
if (this.currentBluePosition == 'left' ) {
Tweener.addTween(blue, {x:638, time:1, onComplete:onBlueMoved})
} else if (this.currentBluePosition == 'right') {
Tweener.addTween(blue, {x:166, time:1, onComplete:onBlueMoved})
}
}
function onBlueMoved () {
if (this.currentBluePosition == 'left') {
this.currentBluePosition = 'right';
} else if (currentBluePosition == 'right') {
this.currentBluePosition = 'right';
}
}
hope you get the idea, because afterwards, there is always room for
improvement ;)
have fun :)
cedric
> Hi all... Apologies up front.
>
> New to email lists and Tweener and AS3 so am probably going to be a
> royal pain in the proverbial... Please let me know if this is not
> the way to do things.
>
> I have the following AS
>
> if (blue.x==166) {
> blue.blue_BTN.addEventListener ('mouseUp', function() {
> Tweener.addTween(blue, {x:638, time:1});
> trace('this is 638')
> });
> }
>
> else if (blue.x==638) {
> blue.blue_BTN.addEventListener ('mouseUp', function() {
> Tweener.addTween(blue, {x:166, time:0.5});
> trace('this is 166')
> });
> }
>
>
>
> What I am trying to do is click blue_BTN and it change position
> (this works). When that is done I want to be able to click on it
> again and restore its position (this doesn’t work).
>
> Is it an if/else thing or is there a tween function I am not
> implementing.
>
> Thanks in advance if anyone can point me in the right direction.
>
> Nathan
>
>
> --
>
> _______________________________________________
> Tweener mailing list
> Tweener at lists.caurinauebi.com
> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
More information about the Tweener
mailing list