VideoHive

as3 tweening problem

438 posts
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Gold Mo Grower
  • Has been a member for 5-6 years
+4 more
dxc381 says

I am going crazy here. I have a couple simple tween functions in as3. They usually work fine, but sometimes they only partially tween and stop. When I open it in the html page it always breaks the first time. When I refresh it works fine.

function tweenAlpha(getMcName, endTween:Number, tweenTime:Number, killAfter:Boolean):void{
    var tweenAlphaTween = new Tween(getMcName, "alpha", easeType, getMcName.alpha, endTween, tweenTime, true);
    //if this is true the child gets removed when the motion is finished 
    if(killAfter == true){
        tweenAlphaTween.addEventListener("motionFinish", finishedTween);
        function finishedTween(event:Event):void {
            main_mc.removeChild(getMcName);
        }
    }
}

Thanks!

690 posts
  • Bought between 10 and 49 items
  • Canada
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 1 000 and 5 000 dollars
geoken says

Are there any tweens being created while that object is tweening?

The problems you describe are the main reason I ditched the native tween classes. They seem to have a lot of issues with overwriting themselves.

2984 posts
  • Community Superstar
  • Has been a member for 5-6 years
  • Won a Competition
  • Sold between 50 000 and 100 000 dollars
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
  • Europe
+1 more
wickedpixel says

heh… that is a bug in actionscript 3…
The garbage collector engine who’s job is to delete unused stuff sometimes deletes the Tweens instances and stops the animations… since i discovered this bug i use only Tweener animation class…

That bug is very annoying expecially when you have listeners added to the Tweens, like you have there :)

is not about the number of the tweens… i saw some files on flashden that freeze right on the fade-in of the logo at the beginning :)

755 posts
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 500 and 999 users
  • Sold between 100 000 and 250 000 dollars
skyplugins says

Hi dxc381,

Seems like you store your tweens in local function variables. In that way they might be garbage collected before they finish their motions. Declare them as class variables and this is the best practice for scripting tweens.

438 posts
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Gold Mo Grower
  • Has been a member for 5-6 years
+4 more
dxc381 says

Thanks guys. That all makes sense now. I thought I was going to punch holes in my computer. I am still pretty new to as3 so your help is very appreciated.

1234 posts
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
  • United States
MBMedia says

A function within a function is not good for AS3 , put your second function out as a separate one.

107 posts
  • Has been a member for 4-5 years
  • Sold between 100 and 1 000 dollars
the_asman says

you have some scooping issues

first you are creating the tweenAlphaTween inside the function this isnt always bad but in your care it is because you are calling on the function before the first tween is done which will give some very odd and unexpected results.

second your callback function is a nested function this is also bad. this is a form of closure and if not implemented correctly can be devestating to your code and garbage collection. you can not assume the flash garbage collection will work the way you want when you use closure.

a quick google search turned up info on javascript closure but it still applies Closure

and thirdly you may want to test if the tweenAlphaTween.isPlaying( ) and not let it rerun the tween if it is

the following code is corrected but it is not tested and also without knowing more of your code i can not tell if it will give the effect you are looking for.

var tweenAlphaTween:Tween
function tweenAlpha(getMcName, endTween:Number, tweenTime:Number, killAfter:Boolean):void{
if ( ! tweenAlphaTween.isPlaying( ) ){
tweenAlphaTween = new Tween(getMcName, “alpha”, easeType, getMcName.alpha, endTween, tweenTime, true);
//if this is true the child gets removed when the motion is finished
if(killAfter == true){
tweenAlphaTween.addEventListener(“motionFinish”, finishedTween);
}
}
}
function finishedTween(event:Event):void {
main_mc.removeChild(getMcName);
}

7339 posts
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 5-6 years
  • United Kingdom
  • Contributed a Tutorial to a Tuts+ Site
  • Won a Competition
  • Contributed a Blog Post
  • Beta Tester
  • Bought between 50 and 99 items
+4 more
MSFX moderator says

@dxc381 dude use Tweener rather than the built in stuff, SO much nicer, far more control :)

438 posts
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Gold Mo Grower
  • Has been a member for 5-6 years
+4 more
dxc381 says

Wow. In reference to the Tweener, how on earth did I do this stuff without it? That thing is 100x better than what I was trying to do. My code is so much cleaner now. I’m sure you guys just made my life a lot easier on many a project. Thanks!

by
by
by
by
by