Link to home
Start Free TrialLog in
Avatar of Kuroz
Kuroz

asked on

Slide in and out using Tween

Hi experts

I'm having problem creating slide in and out event.

I've created a mc called Screen1 with another .swf file loaded. Then I have a button that controls the Screen1's loadMovie. When you click the button, Csel.swf will replace the earlier swf. So far everything works.

Then I want to create a slide in effect. When I click the button, the Screen1 slides in with Csel.swf loaded. Here's where I'm stuck.

Before Screen1 slides in with the new swf loaded, I want it to slide out of the screen before sliding in with the new swf. Which makes it looks like the old screen slides off the screen then a new one appear from the other side.

May I request experienced Flash developers to take a look at the code and help me out.

I'm using Flash CS4 AS2. I'm new to AS that's why I'm using 2 not 3.
Btn1.onRelease = function (){
	if (_root.Screen1._x = 0){
	var SlideIn:Tween = new Tween (_root.Screen1, "_x", Strong.easeOut, 0, -1500, 1, true);
	}
	if (_root.Screen1._x = -1500){
		var SlideIn:Tween = new Tween (_root.Screen1, "_x", Strong.easeOut, 1500, 0, 1, true);
	}
	_root.Screen1.loadMovie ("Csel.swf", 1);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of biyik
biyik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kuroz
Kuroz

ASKER

Wow that's a lot scripting.. took me time to break them down and try to understand it.. I've tried the code you've provided, but it's not fully working.. Ths slide did slide out of the screen and I'm getting output saying slide out complete and loadmovie complete, but it won't slide back in from the other side. Do wonder what's the cause, trying to figure out myself but as a newbie it's mostly near impossible. Please help again.
import mx.transitions.Tween;
import mx.transitions.easing.*
 
var cselActive:Boolean = false;
 
Btn1.onRelease = function (){
	Btn1.enabled = false;
	if (cselActive == false) {
	var SlideOut:Tween = new Tween (_root.Screen1, "_x", Strong.easeOut, 0, -1500, 1, true);
	cselActive = true;
	SlideOut.onMotionFinished = function (){
		trace ("Slide Out Complete");
		_root.Screen1.loadMovie ("Csel.swf", 1)
		trace ("loadMovie function called");
		Btn1.enabled = true;
	}
	}
	else{
	var SlideIn:Tween = new Tween (_root.Screen1, "_x", Strong.easeOut, 1500, 0, 1, true);
	Btn1.enabled = false;
	cselActive = true;
	SlideIn.onMotionFinished = function (){
		trace ("Slide In Complete!");
		Btn1.enabled = true;
	}
	}
}

Open in new window

I guess I couldn't understand what you need. Because in the code I gave first you press a button and a movieclip slides and loads its content. Than if you press it again it slides back to the original position with the loaded content.
Avatar of Kuroz

ASKER

Never mind. I've found a solution. All I need to do is to use "onMotionFinished"..

Btn1.onRelease = function (){
	var SlideOut:Tween = new Tween (_root.Screen1, "_x", Strong.easeOut, 0, -1000, 1, true);
	SlideOut.onMotionFinished = function (){
		var SlideIn:Tween = new Tween (_root.Screen1, "_x", Strong.easeOut, 1000, 0, 1, true);
		_root.Screen1.loadMovie ("Csel.swf", 1);
	}
}

Open in new window

So you have my assistance from the code line "SlideOut.onMotionFinished = function ()"