A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [f8]Keep track of the current page

Hybrid View

  1. #1
    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 07:46 PM. Reason: no title

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    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.

  3. #3
    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.

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