Jump to content
Search Community

Tweening to another frame then resuming functions in that frame

LanLing test
Moderator Tag

Recommended Posts

Hello, I ran into another problem with the little slideshow I'm trying to do. Thanks for everyone who helped me with this previously.

I have a simple sliding animation set up in for frame 1 of a class:

public function slideShow():void {

  menuLeftSide.mainMenuSlideShow.x = 1040; //reset slideshow position

menuLeftSide.mainMenuSlideShow.cacheAsBitmap = true;
  menuLeftSide.menuSlideShowMask.cacheAsBitmap = true;
  menuLeftSide.mainMenuSlideShow.mask = menuLeftSide.menuSlideShowMask;

  var slideShowTween:TweenLite = TweenLite.to(menuLeftSide.mainMenuSlideShow, 70, {x:-1350, ease:Linear.easeNone, onComplete:loop});

  function loop():void {
slideShowTween.restart();
  }

 }

This works fine, however when I go to another frame in the same class, then come back to frame 1 with the slideshow, the slideshow won't resume anymore, because "menuLeftSide.mainMenuSlideShow" (the slideshow image) would be null.

 

This is the code I use to go to another frame. Destination frame is completely new keyframe and completely different from frame 1.

 

if (e.target.name == "character1Link") { //when clicking character1Link
TweenLite.to(menuLeftSide, 0.2, {alpha:0, onComplete:sendMenuToFrameLeft, onCompleteParams:[10]}); //go to frame 10
TweenLite.to(menuLeftSide, 0.2, {alpha:1, delay:0.2});
}

 

Then coming back to frame 1 and resuming slideshow:

 

if (e.target.name == "backToMain") { when clicking backToMain link
TweenLite.to(menuLeftSide, 0.2, {alpha:0, onComplete:sendMenuToFrameLeft, onCompleteParams:[1]}); //go back to frame 1
TweenLite.to(menuLeftSide, 0.2, {alpha:1, delay:0.2});
slideShow(); //<--- this returns the null error
}

 

How would I set it so that when I go back to frame 1, the slideshow would immediately exist and be ready for use for the slideShow() function?

 

Thanks.

Link to comment
Share on other sites

don't use the var keyword inside the slideShow() constructor method. once you do that you can only access slideShowTween from that method

 

 

create the var outside of slideShow();

public var slideShowTween:TweenLite 

 

and the inside slideShow() give it a value

 

 

slideShowTween = TweenLite.to(menuLeftSide.mainMenuSlideShow, 70, {x:-1350, ease:Linear.easeNone, onComplete:loop});

 

http://ntt.cc/2009/04/28/beginning-actionscript-3-scope.html

Link to comment
Share on other sites

I declared it as a public variable outside the functions and defined slideShowTween in slideShow() like you showed, but it still throws the null error. =/

It actually thinks the slideshow image, mainMenuSlideShow, is null, since I did a trace:

TweenLite.to(menuLeftSide, 0.2, {alpha:0, onComplete:sendMenuToFrameLeft, onCompleteParams:[1]}); //go to frame 10, portrait luo
TweenLite.to(menuLeftSide, 0.2, {alpha:1, delay:0.2});
//slideShow();
trace(menuLeftSide.mainMenuSlideShow);

However the weird thing is the slideshow image is visible on stage at this default position (the position I put it in Flash), it's just not moving.

Link to comment
Share on other sites

well at least now you know it isn't the tween.

 

is menuLeftSide.mainMenuSlideShow persistent throughout all the frames of your animation?

you mentioned a few times that you play through a bunch of frames. if you remove menuLeftSide.mainMenuSlideShow from the stage at any point (blank key frame) or perhaps have instances in multiple keyframes, that could certainly cause Flash to not know what menuLeftSide.mainMenuSlideShow is supposed to be pointing at.

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