I'm using the Tween class to fadeIn, Pause, and fadeOut an image in Flash 8.
I have functions that work in a loop - loadImage function triggers fadeIn triggers Pause triggers fadeOut triggers loadImage etc...
This is all working dandy. However, I want to be able to click a thumbnail and whatever tween it's doing should stop, and jump to the fadeOut function, which would then call the load function, starting the process over. What's actually happening when I click the thumbnail is it does jump to fadeOut, but the other tween doesn't stop, so I now have multiple loops going on (like Row, Row, Row Your Boat in staggered choruses).
I've tried giving the instances of myTween different names, I've tried myTween.stop(), but it doesn't help. I just keep getting competing function loops.
Well without seeing any code it's tough to see what you're doing...but if you are creating your tween in an object...like var myTween:Tween = new Tween(params); then you can use myTween.stop() to stop the tween or also myTween.fforward() to send the tween to the end of its transition.
...attached in txt format. I'd be psyched if you could help. It's all working fine, except for the doubled over looping. The thumb buttons call forceLoadImage(). Maybe I just need to use fforward if that has been called until I'm back to fadeOut?
(By the way - Allentown? My family's from Allentown!)
Dang - that seems to have done it. I'm going to have to study what you did to see if I can make sense of it. Might send a couple questions your way to clear things up so I don't have to ask again next time. Thanks!
Don't get to Allentown too often since there's no family left there, but occasinally go out of the way for some Yocco's.
Sweet...I wasn't sure since I was just coding blindly...glad it worked out for you.
Let me know if you have any questions...that's what we are all here for.
Yes, love me some Yocco's...and can never get enough Brass Rail cheese steaks...
In case you have the time and inclination, I have a few questions about why it works. Obviously I've gotten into some programming that's a little beyond me and I'm trying to make sense of it. You've been a great help so far - thanks.
function forceLoadImage(lgImageURL) {
//create a reference to this
var ref = this;
/************************
Why do we have to create a reference to this instead of just using this?
What exactly does this refer to - I thought it was just the movie clip we're in, or is it the function or something else?
************************/
for (var w = 0; w<_parent.imageArray.length; w++) {
if (lgImageURL == _parent.imageArray[w]) {
slideNumber = w;
w = parent.imageArray.length;
//stop our tween
ref.stopTween(myTween);
ref.fadeOut();
/****************************
Based on the question above, why not just
this.stopTween(myTween)
For that matter, why doesn't stopTween(myTween) work?
And why do we need an outside function -
why not myTween.stop()?
***************************/
}
}
}
//define function to stop our tween
function stopTween(theTween:Tween){
trace("stop the tween");
theTween.stop();
}
//callback for when a tween change occurs
myTween.onMotionChanged = function(){
trace("a tween was changed");
}
/*****************
This last function never gets called, no matter where in a tween I hit a thumbnail
******************/
/************************
Why do we have to create a reference to this instead of just using this?
What exactly does this refer to - I thought it was just the movie clip we're in, or is it the function or something else?
************************/
The reference to this is made because flash is quircky and goes out of scope, not letting us access functions that we should have access to. So we bring flash back into scope by using var ref = this; at the level where we want access. We can't just use "this" alone" because then flash will only look on the object where the call is made. By storing this in a variable, flash references the object where the reference was stored, not where it gets called, as is the case with just using 'this'.
Originally Posted by MOGE
/****************************
Based on the question above, why not just
this.stopTween(myTween)
For that matter, why doesn't stopTween(myTween) work?
And why do we need an outside function -
why not myTween.stop()?
***************************/
Using this here would reference the for loop, we want to reference a scope above that, so we store the reference...see my first explanation
The outside function was created to prevent scoping issues and for ease of resuse.
Originally Posted by MOGE
/*****************
This last function never gets called, no matter where in a tween I hit a thumbnail
******************/
hmmm....maybe we need to define that in a function and then call the function from the same place you are definining the tween. Try pasting that code where you call your onMotionFinished and see if it gets called there..
Originally Posted by MOGE
(Josh Early candies, too.)
yes indeed! or dorney park and wild water kingdom!
Gotcha. That makes sense. So maybe some of the times I was getting confused about scope it was Flash, not me? I'll just go on thinking that, anyway. Thanks for all your help.