A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Creating a back button AS3

Hybrid View

  1. #1
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is one that remembers all pages visited and stores them in an array, then removes it from the array as you go back, perhaps this is more of what you desire, play around with it.

    actually I changed the code on that file, here it is, if you wish to swap it for this code.
    PHP Code:
    stop();

    import flash.events.MouseEvent;

    var 
    i:Number;
    var 
    firstRun:Boolean;

    var 
    currentPage:Number;
    var 
    pageArray:Array;
    var 
    buttonArray:Array;

    if (! 
    firstRun)
    {
        
    currentPage 1;
        
    firstRun true;
        
    pageArray = new Array();
        
    pageArray.push(currentPage);
        
    buttonArray = new Array(button1,button2,button3,button4,button5);
        for (
    0buttonArray.lengthi++)
        {
            var 
    pageButton:Object buttonArray[i];
            
    pageButton.value = (1);
            
    pageButton.numText.text = (1);
            
    pageButton.addEventListener(MouseEvent.CLICKdoPage);
        }
        
    backButton.addEventListener(MouseEvent.CLICKgoBack);
        
    stage.addEventListener(Event.ENTER_FRAMEshowHide);
    }

    function 
    showHide(e:Event):void
    {
        if (
    pageArray.length 1)
        {
            
    backButton.visible true;
        }
        else
        {
            
    backButton.visible false;
        }
    }

    function 
    doPage(e:MouseEvent):void
    {
        
    currentPage e.currentTarget.value;
        
    pageArray.push(currentPage);
        
    gotoAndStop(currentPage);
    }

    function 
    goBack(e:MouseEvent):void
    {
        if (
    pageArray.length 1)
        {
            
    pageArray.pop();
            
    gotoAndStop(pageArray[pageArray.length 1]);
        }

    Last edited by fruitbeard; 02-04-2015 at 11:49 AM.

  2. #2
    Junior Member
    Join Date
    Feb 2015
    Posts
    6
    Looks good, I will try this once I get home from work and will post my file then as well.

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