[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

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

0
Kuroz
Asked:
Kuroz
  • 3
  • 2
1 Solution
 
biyikCommented:
Hi!
First of all you need to import the tween class
import mx.transitions.Tween;
import mx.transitions.easing.*;

Secondly, you can create a variable to follow which slide is active. For instance:
var activeMovie:String = "csel";
Or, you can create a boolean:
var cselActive:Boolean = false;
Then you can write your if statement...

Finally, let's code:
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 (Btn1, "_x", Strong.easeOut, 0, 10, 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 (Btn1, "_x", Strong.easeOut, 10, 0, 1, true);
Btn1.enabled = false;
cselActive = false;
SlideIn.onMotionFinished = function() {
trace("Slide In Complete!");
Btn1.enabled = true;
}
}}

Open in new window

0
 
KurozAuthor Commented:
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

0
 
biyikCommented:
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.
0
 
KurozAuthor Commented:
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

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now