FORUMS: list search recent posts

Tweening with ActionScript

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
downtownguy
Tweening with ActionScript
on Feb 7, 2006 at 10:09:31 am

Hi Again...

I am trying to learn how to animate using ActionScript. So far, I am moving an oject from the right side of the stage to the left. As the object gets close to the middle, its alpha transparency goes from 0 to 100.

I was wondering how to get the object's alpha transparency back to zero before it exits on the left side of the stage. Here's the script so far:

import mx.transitions.Tween;
import mx.transitions.easing.*;

var myLogoMoveX = twLogoMoveX:Tween = New Tween(myLogoMC, "_x", Strong.easeOut, 700, -200, 12, true);
var myLogoMoveA = twLogoMoveA:Tween = New Tween(myLogoMC, "_alpha", Strong.easeOut, 0, 100, 4, true);

// Thanks in advance! :)



Return to posts index

lajoiet
Re: Tweening with ActionScript
on Feb 7, 2006 at 2:00:50 pm

OK, looking at your tween scripts, you have the object moving from X coordinate 700 to X coordinate -200 over 12 seconds. I assume that is starting outside your stage and going from one side right out the other.

At the same time, you have it's _alpha value changing from 0 to 100 over 4 seconds.

there are a few ways you could approach this. One would be to change the _alpha tween to 6 seconds which would be 1/2 of the 12 second motion tween. Then watch for the _alpha tween to be complete and initiate another _alpha tween from 100 to 0 like this:

var myLogoMoveX = twLogoMoveX:Tween = New Tween(myLogoMC, "_x", Strong.easeOut, 700, -200, 12, true);
var myLogoMoveA = twLogoMoveA:Tween = New Tween(myLogoMC, "_alpha", Strong.easeOut, 0, 100, 6, true);

myLogoMoveA.onMotionStopped = function() {
myLogoMoveB = twLogoMoveB:Tween = New Tween(myLogoMC, "_alpha", Strong.easeOut, 100, 0, 6, true);
}

Another way would be to just do the motion tween, and set up a loop that continually updated myLogoMC._alpha based on the X coordinate. I'm assuming based on your motion tween that your stage is 500 pixels wide.

var myLogoMoveX = twLogoMoveX:Tween = New Tween(myLogoMC, "_x", Strong.easeOut, 700, -200, 12, true);

this.createEmptyMovieClip("changeAlpha",this.getNextHighestDepth());
changeAlpha.onEnterFrame = alphaChange;

myLogoMovex.onMotionStopped = function() {
delete changeAlpha.onEnterFrame;
delete changeAlpha;
}

function alphaChange () {
if (myLogoMC._x =< 250) {
myLogoMC._alpha = ((myLogoMC._x/250)*100);
}
if (myLogoMC._x < 250) {
myLogoMC._alpha = (((-(myLogoMC._x-500))/250)*100);
}

This will make the logo hit transparent at coordinates 0 and 100. If you want it to hit transparent at -200 and 700, you would modify the alphachange function like this:


function alphaChange () {
if (myLogoMC._x =< 250) {
myLogoMC._alpha = (((myLogoMC._x+200)/450)*100);
}
if (myLogoMC._x < 250) {
myLogoMC._alpha = ((-(myLogoMC._x-700)/450)*100);
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]