A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [F8] Tween Class troubles

  1. #1
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29

    [F8] Tween Class troubles

    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.

    Any suggestions?

    Thanks

  2. #2
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    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.

    So on your button you could say:

    thumbnail_btn.onRelease = function(){
    myTween.stop();
    fadeOut();
    }

    If that's what you are already doing then please either post code samples or your .fla.

    Thanks

  3. #3
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29

    Here's the code...

    ...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!)
    Attached Files Attached Files

  4. #4
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    give this a shot...not sure what it will do...

    Code:
    this._alpha = 0;
    thisVisible = false;
    slide1._alpha = 0;
    slideNumber = 0;
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    //define our tween here to make accessible
    var myTween:Tween;
    function onLoadInit(mc:MovieClip) {
    	slide1._x = (bgroundArea._width-slide1._width)/2;
    	if ((slideNumber+3)>=(_parent.imageArray.length)) {
    		slideNumber = 0;
    	} else {
    		slideNumber = slideNumber+3;
    	}
    	if (thisVisible == false) {
    		slide1._alpha = 100;
    		myTween = new Tween(this, "_alpha", None.easeNone, this._alpha, 100, _parent.fadeTime, true);
    		myTween.onMotionFinished = function() {
    			if (forceLoad == true) {
    				autoLoadImage();
    				forceLoad = false;
    			}
    			//trace("end of initial fade in");
    			thisVisible = true;
    			imagePause();
    		};
    	} else {
    		//trace("starting fade in");
    		myTween = new Tween(slide1, "_alpha", None.easeNone, slide1._alpha, 100, _parent.fadeTime, true);
    		myTween.onMotionFinished = function() {
    			if (forceLoad == true) {
    				autoLoadImage();
    				forceLoad = false;
    			}
    			//trace("end of regular fade in");
    			imagePause();
    		};
    	}
    }
    function imagePause() {
    	myTween = new Tween(slide1, "_alpha", None.easeNone, 100, 100, _parent.pauseTime, true);
    	myTween.onMotionFinished = function() {
    		if (forceLoad == true) {
    			autoLoadImage();
    			forceLoad = false;
    		}
    		//trace("end of pause");
    		fadeOut();
    	};
    }
    function fadeOut() {
    	myTween = new Tween(slide1, "_alpha", None.easeNone, slide1._alpha, 0, _parent.fadeTime, true);
    	myTween.onMotionFinished = function() {
    		if (forceLoad == true) {
    			forceLoad = false;
    		}
    		//trace("end of fade out");
    		autoLoadImage();
    	};
    }
    function autoLoadImage() {
    	var mcLoader:MovieClipLoader = new MovieClipLoader();
    	mcLoader.addListener(this);
    	mcLoader.loadClip(_parent.imageArray[slideNumber], slide1);
    }
    function forceLoadImage(lgImageURL) {
                //create a reference to this
    	var ref = this;
    	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();
    		}
    	}
    }
    
    //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");
    }
    
    
    autoLoadImage();
    Your family is really from Atown!? Wow...what a small world. I love the Lehigh Valley. Do you get to visit this area much?

  5. #5
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29
    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.

  6. #6
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    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...

  7. #7
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29

    It's working...

    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
    ******************/


    (Josh Early candies, too.)

  8. #8
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    Quote Originally Posted by MOGE
    /************************
    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'.


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


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


    Quote Originally Posted by MOGE
    (Josh Early candies, too.)
    yes indeed! or dorney park and wild water kingdom!

  9. #9
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center