Jump to content
Search Community

Set variables on complete

peterdavidsson test
Moderator Tag

Recommended Posts

Hi,

How do I set som variables onComplete without creating a function?

 

For example:

var mytextvar1:String;

var mytextvar2:String;

 

TweenMax.delayedCall(1, {onComplete:mytextvar1 = "red", mytextvar2 = "blue"})

 

And how would I change the visibility on complete?

TweenMax.to(imagesArray.background, 0.25, {alpha:1, onComplete:picturesArray.visible = false})

 

(using TweenMax AS3...)

 

thankful for any help! ;) /Peter

Link to comment
Share on other sites

Why are you trying to avoid writing a function? Be careful about creating anonymous functions or little shortcuts like that because it can come back to bite you - it's less readable and can cause garbage collection problems in Flash.

 

As far as setting visible to false at the end of a tween, just use the visible property (VisiblePlugin):

 

TweenMax.to(picturesArray[i].img_bg, 2, {alpha:0, visible:false)});

 

Or better yet, use the autoAlpha property since you're fading the alpha to zero anyway - autoAlpha just intelligently toggles visible to false whenever the alpha is zero:

 

TweenMax.to(picturesArray[i].img_bg, 2, {autoAlpha:0)})

 

Check out the Plugin Explorer for a bunch of other stuff you can do. http://www.tweenmax.com

Link to comment
Share on other sites

thanks!! I know I'm a bit lazy sometimes.. thats why I'm not writing a function ;) I've understand I need to structure my programming a bit and upgrade my skills.

 

That solved my problem for now but I still doesn't know how to pass a value to the function with complete for example:

 

TweenMax.to(picturesArray[i].img_bg.another_mc, 2, {x:300, onComplete:setsomeText(picturesArray[i]) } );

public function setsomeText(myMovieClip):void {
    myMovieClip.text_mc.thetext.htmlText = "hello";
   trace(myMovieClip)
}

 

/P

Link to comment
Share on other sites

That's what the onCompleteParams special property is for:

 

TweenMax.to(picturesArray[i].img_bg.another_mc, 2, {x:300, onComplete:setsomeText, onCompleteParams:[picturesArray[i]] } );

public function setsomeText(myMovieClip):void {
    myMovieClip.text_mc.thetext.htmlText = "hello";
   trace(myMovieClip);
}

 

You can pass any number of parameters to your function - just populate the onCompleteParams Array with as many as you want.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...