Jump to content
Search Community

add and remove child

chefkeifer test
Moderator Tag

Recommended Posts

why can't i get this to work. am i missing something here

 

clsBtn.alpha = 0;
clsBtn.buttonMode = true;
clsBtn.addEventListener(MouseEvent.CLICK, exitSurvey)
surveyBtn.buttonMode = true;
surveyBtn.addEventListener(MouseEvent.CLICK, enterSurvey);
function enterSurvey (e:MouseEvent):void {
var newSurvey:survey = new survey();
this.addChild(newSurvey);
var enterSur:TimelineMax = new TimelineMax();
       enterSur.insert(TweenMax.to(newSurvey, 0, {alpha:0, x:450, y:375}));
	enterSur.appendMultiple(TweenMax.allTo([newSurvey, clsBtn], 1, {alpha:1}));
}
function exitSurvey (e:MouseEvent):void {
var exitSur:TimelineMax = new TimelineMax();
	exitSur.appendMultiple(TweenMax.allTo([newSurvey, clsBtn], 1, {alpha:0, onComplete:this.removeChild, onCompleteParams:[newSurvey]}));
}

Link to comment
Share on other sites

You didn't describe exactly what's not working, but I did notice that you're declaring a local newSurvey variable inside enterSurvey() and then you try to reference that variable inside your exitSurvey() function. Can't do that - local variables only exist inside the function in which they're declared.

 

Also, why are you using a TimelineMax? It looks like your tweening needs are very simple and you're not controlling all the tweens as a group or anything, so there's really no reason to put them into a TimelineMax. I mean you can - it won't mess anything up. It's just a bit wasteful.

Link to comment
Share on other sites

I understand teh timelineMax part.. i was just copying and pasting and was going to clean that part of the code up later..but i am not understanding how to remove the child with a tween. essentially i just want to be able to click the button and the movieclip appears on the stage and then when they click the "x" button..ie "clsBtn" the movieclip will exit the stage with a tween...

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...