To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-28-2006, 08:43 PM   #1
jsfaulds
Junior Member
 
Join Date: Oct 2006
Posts: 11
[f8]Keep track of the current page

Hi hope someone can help

On the stage, i have three buttons called, button1,2,3 In the Library, I have three movie clips called, page1 page2 page3.
When the movie loads page1 is loaded and when you click on button2 page1 fades out and page2 fades in
Then press on button1, page2 fades out and page1 fades back in again.
All's well with the code and two buttons.

My problem is when i try to add button3 I cant get the current page code to work.
At the moment all the ( var currentPage = "page1"; ) code is doing is stoping the current page fading in again when your on that page.

could someone help with some code that will Keep track of the current page

This is the code for the two buttons

import mx.transitions.Tween;
import mx.transitions.easing.*;
var currentPage = "page1";

var page1:MovieClip = this.attachMovie("page1","page1",10);
page1._x = Stage.width/2;
page1._y = Stage.height/2;


button1.onRelease = function() {
if(currentPage !="page1") {
var fadeout:Tween = new Tween(page2,"_alpha",Strong.easeOut,100,0,1,true);
fadeout.onMotionFinished = function() {
var page1:MovieClip = _root.attachMovie("page1","page1",10);
page1._x = Stage.width/2;
page1._y = Stage.height/2;
page1._alpha = 0;

var fadein:Tween = new Tween(page1,"_alpha",Strong.easeOut,0,100,1,true);
currentPage = "page1";
}
}
}

button2.onRelease = function() {
if(currentPage !="page2") {
var fadeout:Tween = new Tween(page1,"_alpha",Strong.easeOut,100,0,1,true);
fadeout.onMotionFinished = function() {
var page2:MovieClip = _root.attachMovie("page2","page2",10);
page2._x = Stage.width/2;
page2._y = Stage.height/2;
page2._alpha = 0;

var fadein:Tween = new Tween(page2,"_alpha",Strong.easeOut,0,100,1,true);
currentPage = "page2";
}
}
}

Last edited by jsfaulds; 10-28-2006 at 08:46 PM. Reason: no title
jsfaulds is offline   Reply With Quote
Old 10-29-2006, 02:28 AM   #2
jAQUAN
Total Universe Man
 
jAQUAN's Avatar
 
Join Date: Jul 2000
Location: NaN
Posts: 2,061
It actually works better to store a fully qualified reference in the currentPage variable rather than just the instance name. That's why you record the attachMovie to a variable. Notice I changed "page1" to page1.
Also, clips placed on the stage at author time are on a different range of numbers than clips placed at run time as far as levels go. The only reason your page movies can replace each other is to load to the same level as you are doing, bur rather than place page 1 at author time, trigger button1's onRelease method automatically.

replace your code with this and delete page one off the stage.
Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
//set currentPage to some arbitrary value
var currentPage = 0;
button1.onRelease = function() {
	if (currentPage != page1) {
		var fadeout:Tween = new Tween(currentPage, "_alpha", Strong.easeOut, 100, 0, 1, true);
		fadeout.onMotionFinished = function() {
			var page1:MovieClip = _root.attachMovie("page1", "page1", 10);
			page1._x = Stage.width/2;
			page1._y = Stage.height/2;
			page1._alpha = 0;
			var fadein:Tween = new Tween(page1, "_alpha", Strong.easeOut, 0, 100, 1, true);
			currentPage = page1;
		};
		
	}
};
button2.onRelease = function() {
	if (currentPage != page2) {
		var fadeout:Tween = new Tween(currentPage, "_alpha", Strong.easeOut, 100, 0, 1, true);
		fadeout.onMotionFinished = function() {
			var page2:MovieClip = _root.attachMovie("page2", "page2", 10);
			page2._x = Stage.width/2;
			page2._y = Stage.height/2;
			page2._alpha = 0;
			var fadein:Tween = new Tween(page2, "_alpha", Strong.easeOut, 0, 100, 1, true);
			currentPage = page2;
		};
		
	}
};
button3.onRelease = function() {
	if (currentPage != page3) {
		var fadeout:Tween = new Tween(currentPage, "_alpha", Strong.easeOut, 100, 0, 1, true);
		fadeout.onMotionFinished = function() {
			var page3:MovieClip = _root.attachMovie("page3", "page3", 10);
			page3._x = Stage.width/2;
			page3._y = Stage.height/2;
			page3._alpha = 0;
			var fadein:Tween = new Tween(page3, "_alpha", Strong.easeOut, 0, 100, 1, true);
			currentPage = page3;
		};
		
	}
};
//trigger button1's onRelease.
button1.onRelease();
P.S. If you look into for loops, you can write the code for all 3 buttons at once.
__________________
I approve this message.
AS3SOURCE: @ @ @ @
SD | fk css | Believe the HYPE | I tweet.
I hate it when I sit down to play a game of Monopoly and later realize that I have just lost $400 playing pai gow poker. - creativeinsomnia
jAQUAN is offline   Reply With Quote
Old 10-29-2006, 03:28 AM   #3
jsfaulds
Junior Member
 
Join Date: Oct 2006
Posts: 11
Thanks so much it works great, maybe i'll be able to sleep now

Last edited by jsfaulds; 10-30-2006 at 04:11 PM.
jsfaulds is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:16 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.