Jump to content
Search Community

Set visibility in tween / call method instead of function

GreenBeak test
Moderator Tag

Recommended Posts

Hi,

 

I would like to set the visibility of a movie clip onReverseComplete. Is there a way to call a method (.visible = false) in onReverseComplete or any other way, instead of creating a function that solely is responsible for calling

movieClip.visible = false;
Link to comment
Share on other sites

Using the anonymous function didn't work for me. I get the following error message:

TypeError: Error #1010: A term is undefined and has no properties.
    at MethodInfo-245()
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at com.greensock::TweenLite/render()
    at com.greensock.core::SimpleTimeline/render()
    at com.greensock.core::Animation$/_updateRoot()

I haven't tried TimelineLite, however, I noticed that there is a difference in using a function to set the visibility and setting the visible attribute in the tween directly.

 

Strangely enough, these two codes don't work the same, although one would expect so:

var tween = new TweenLite(mc, 0.5, {visible:false});
var tween = new TweenLite(mc, 0.5, {onComplete:setVisibility, onComplete:[mc,false]});

function setVisibility(mc:MovieClip, state:Boolean) {
    mc.visible = state;
}

In the first case the mc gets hidden correctly, but visible has the feature that the mc is not listening to EventListeners anymore. However, setting the visible attribute directly in TweenLite still triggers the EventListener, whereas calling a function to do so correctly disables any EventListener dispatches.

 

Anyone know why?

Link to comment
Share on other sites

Well I guess mc is not accessible in that scope for some reason, so just pass it as a parameter

TweenLite.to(mc, 1, {
  x:0,
  onReverseComplete:function(mc){ mc.visible = false },
  onReverseCompleteParams:[mc]
});

If you aren't using TweenMax, have you made sure that VisiblePlugin is activated? I'm not too sure why you'd see such behaviour unless there's something else going on in your code. It's not like GSAP is somehow setting a special, misbehaving mc.visible property to false...

  • Like 2
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...