A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Tween Class Issues

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1

    Tween Class Issues

    Alright, first off, thanks for taking a look at this. This is a project for my Flash II class in school. What is going on in the code is; slideBack_mc is a movie clip that contains 5 other movie clips, home, indie, punk, metal and rock. Those movie clips have a button within them, and when the button is pressed, slideBack_mc should slide(Tween) across the stage, to center the movie clip that was pushed(ex. press home, and it will slide to the middle of the stage). Now up to this point I have no issues getting it to work. But my problem is; when I click on the movie clip(home, rock etc..) the tween will occur, but the starting x position is pre-determined. I would like to set it up to where my start position for my tween class is actually the "slideBack_mc"'s current x position. I have tried using ENTER_FRAME, and can get it to output the current x position in the output window. But I can't seem to get that same position to become a variable that I can use as my tween classes starting position.

    If you have any questions or things don't make sense(plausible) please let me know and I'll try to explain further. But any ideas on the direction I should go would be awesome, I feel like I'm close, I'm just missing a link in the chain.

    (Also the movie clips within slideBack_mc, are supposed to shrink when they are not highlighted, and grow when they are the main focus, so there is some code applied to the indie movie clip to do so, that's why that is there.)

    Thankfully,

    -Nate Steven


    Code:
    stop();
    
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent; 
    
    
    home.addEventListener(MouseEvent.CLICK, gotoPage);
    punk.addEventListener(MouseEvent.CLICK, gotoPage);
    indie.addEventListener(MouseEvent.CLICK, gotoPage);
    rock.addEventListener(MouseEvent.CLICK, gotoPage);
    metal.addEventListener(MouseEvent.CLICK, gotoPage);
    
    function gotoPage(evtObj:MouseEvent)    {
    	trace("the " + evtObj.target.name + " button was pushed")
    	gotoAndStop(evtObj.target.name);
    }
    
    addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
    
    function fl_EnterFrameHandler(event:Event):void
    {
    	//Start your custom code
    	// This example code displays (X = and the current x position) in the Output panel.
    	trace("X = "+ slideBack_mc.x);
    	var curXPos=slideBack_mc.x;
    	
    }
    
    
    
    var curXPos:Number = slideBack_mc.x;
    
    var iSlide:Tween = new Tween(slideBack_mc, "x", Elastic.easeOut, curXPos, -47, .5, true);
    var hSlide:Tween = new Tween(slideBack_mc, "x", Elastic.easeOut, curXPos, 336, .5, true);
    var rSlide:Tween = new Tween(slideBack_mc, "x", Elastic.easeOut, curXPos, -430, .5, true);
    var mSlide:Tween = new Tween(slideBack_mc, "x", Elastic.easeOut, curXPos, -813, .5, true);
    var pSlide:Tween = new Tween(slideBack_mc, "x", Elastic.easeOut, curXPos, -1200, .5, true);
    iSlide.stop();
    hSlide.stop();
    rSlide.stop();
    mSlide.stop();
    pSlide.stop();
    
    var iXGrow:Tween = new Tween(slideBack_mc.indieSlide_mc, "scaleX", Strong.easeOut, .5, 1, .5, true);
    var iYGrow:Tween = new Tween(slideBack_mc.indieSlide_mc, "scaleY", Strong.easeOut, .5, 1, .5, true);
    iXGrow.stop();
    iYGrow.stop();
    
    slideBack_mc.indieSlide_mc.i_btn.addEventListener(MouseEvent.CLICK, iXMove);
    function iXMove(evtObj:MouseEvent):void {
    	iSlide.start();
    	iXGrow.start();
    	iYGrow.start();
    trace(slideBack_mc.x + " ");
    }
    
    slideBack_mc.homeSlide_mc.h_btn.addEventListener(MouseEvent.CLICK, hXMove);
    function hXMove(evtObj:MouseEvent):void {
    	hSlide.start();
    	trace(slideBack_mc.x + " ");
    }
    
    slideBack_mc.rockSlide_mc.r_btn.addEventListener(MouseEvent.CLICK, rXMove);
    function rXMove(evtObj:MouseEvent):void {
    	rSlide.start();
    trace(slideBack_mc.x + " ");
    }
    
    slideBack_mc.metalSlide_mc.m_btn.addEventListener(MouseEvent.CLICK, mXMove);
    function mXMove(evtObj:MouseEvent):void {
    	mSlide.start();
    	 trace(slideBack_mc.x + " ");
    }
    
    slideBack_mc.punkSlide_mc.p_btn.addEventListener(MouseEvent.CLICK, pXMove);
    function pXMove(evtObj:MouseEvent):void {
    	pSlide.start();
    	    trace(slideBack_mc.x + " ");
    }
    
    //var curXPos=slideBack_mc.x

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Hi Nate,

    Welcome to FlashKit.

    Use slideBack_mc.x in the tween call instead of curXPos because curXPos is defined when the code runs for the first time and it never gets updated.
    This should be it.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    I'm assuming the tween is always starting from what slideBack_mc's x position is at the beginning? That's because you created the tweens at runtime so you set the starting x values to be that of curXPos, which is whatever slideBack_mc's x position is at runtime. You don't need that enter frame listener for this. Just cut and paste the tweens in their respective listeners. So take iSlide and put it in iXMove, hSlide in hXMove, etc. Also change the tweens so that
    PHP Code:
    hSlide = new Tween (.........., curXPos); change this to
    hSlide 
    = new Tween (.........., slideBack_mc.x); this 
    Edit: Tell me if just doing what nunomira said worked

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