Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Back/Forward Buttons in Actionscript 3.0 (Saving state of application)

Posted on 2008-10-27
2
Medium Priority
?
1,131 Views
Last Modified: 2013-11-11
Hi All,

I have researched everywhere and I coudn't find a solution for my problem. Our project is 90% completed and all it needs now is creating a Back/Forward functionality like any browser/Photoshop etc.. has.

If someone could help me I would appreciate it very much indeed.

My Problem:
-------------------
1 - I am using Actionscript 3.0.
2 - I am using classes, so all actionscript code is within files etc.
3 - There is only 1 frame, so I cannot go back and forward within frames.

My application is sctructured as follow:

1- I have a background image on the left, which is the are where things will show.
2 - A menu on the right hand side with 8 buttons
      2.1 - Each button has it's own event listeners that change what happens on the left hand side.

e.g.
Button 1 will make the background image change, and display a 24x24 grid.
Each grid square is clickable, and if clicked it will show a screen with some information about a company.

Button 2 will make the background image change, and display a 6x6 grid.
Each grid square when clicked will show another grid with different pictures.

etc..etc..

What I would like:
-------------------------------
I have a back/forward button, and I need to be able to navigate back/forward thru everything that happens within the application.

So using my example above.

If I clicked Button1,
then Button 2,  
then the Back Button,
The action from Button1 will be activated and so it would "make the background image change, and display a 24x24 grid.
Each grid square is clickable, and if clicked it will show a screen with some information about a company."

The same would work if I clicked in the forward button, so


If I clicked Button1,
then Button 2,  
then the Back Button,
The action from Button1 will be activated and so it would "make the background image change, and display a 24x24 grid.
Each grid square is clickable, and if clicked it will show a screen with some information about a company."
Then clicked in the Forward, then it will "will make the background image change, and display a 6x6 grid.
Each grid square when clicked will show another grid with different pictures." (same as button2).

---------------
I don't know if I explained very well, but any help would be much appreciated.

P.s.

The application I am creating is exported as an Air File, so its not using a Browser.

Regards,
Dan

0
Comment
Question by:vibrazy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 22843877
hello.
thinking out loud here
if each time you click a button pop it into an array. so the last action will be array[0] - so write a case statement
and based on which item is in the array trigger that code linked to the that btns listeners?
0
 
LVL 5

Author Comment

by:vibrazy
ID: 22848408
Hi blue-genie,

Yeah that is what I had to do. I wish you commented earlier :) Will give you the points tho.

Thanks for your help.

var historyStateCountBack:int = 0;
var historyStateCountNext:int = 0;
var historyFunctions:Array = new Array();
 
 
function init()
{
	//start application
	//1 - set default function to home
	//2 - disable buttons back/next
	historyFunctions[0] = home;
	bk.enabled = false;
	nextbtn.enabled = false;
	//set up program as usual adding listners to buttons etc
	
}
init();
 
 
 
ac1.addEventListener(MouseEvent.CLICK, action1);
ac2.addEventListener(MouseEvent.CLICK, action2);
ac3.addEventListener(MouseEvent.CLICK, action3);
ac4.addEventListener(MouseEvent.CLICK, action4);
ac5.addEventListener(MouseEvent.CLICK, action6("dan",36));
ac6.addEventListener(MouseEvent.CLICK, action6("dan",25));
 
function home(event:MouseEvent)
{
	
	result.text = "Donkey";
	historyStateCountBack = 0;
	historyFunctions[0] = home;
	resetBack();
	addHistory(arguments.callee,event.target.name);
}
 
 
function action1 (event:MouseEvent)
{
	var current_time = new Date(); 
	result.text = "Action1 " + current_time.getHours() + ":" +  current_time.getMinutes() + ":" + current_time.getSeconds();
	
	resetBack();
		
	addHistory(arguments.callee,event.target.name);
 
	
}
function action2 (event:MouseEvent)
{
	var current_time = new Date(); 
	result.text = "Action2 " + current_time.getHours() + ":" +  current_time.getMinutes() + ":" + current_time.getSeconds();
 
	resetBack();
		
	addHistory(arguments.callee,event.target.name);
 
}
function action3 (event:MouseEvent)
{
	var current_time = new Date(); 
	result.text = "Action3 " + current_time.getHours() + ":" +  current_time.getMinutes() + ":" + current_time.getSeconds();
	resetBack();
	
	addHistory(arguments.callee,event.target.name);
 
}
function action4 (event:MouseEvent)
{
	var current_time = new Date(); 
	result.text = "Action4 " + current_time.getHours() + ":" +  current_time.getMinutes() + ":" + current_time.getSeconds();
	
	resetBack();
addHistory(arguments.callee,event.target.name);
	
}
function action5 (event:MouseEvent)
{
	var current_time = new Date(); 
	result.text = "Action5 " + current_time.getHours() + ":" +  current_time.getMinutes() + ":" + current_time.getSeconds();
	
	resetBack();
 
	addHistory(arguments.callee,event.target.name);
	
}
function action6 (s:String,n:int):Function
{
	return function(event:MouseEvent):void
	{
		
		result.text = "Multi " + s + ":" +  n;
		
		resetBack();
	
		addHistory(arguments.callee,event.target.name);
	}
	
}
 
 
function resetBack():void
{
		for(var i:uint = 0; i < historyFunctions.length; i++)
		{
				bk.removeEventListener(MouseEvent.CLICK,historyFunctions[i]);
				nextbtn.removeEventListener(MouseEvent.CLICK,historyFunctions[i]);
		}
}
function addHistory(funcName:*,target:*):void
{
		
			if(target == "bk" || target == "nextbtn")
			{
				if(funcName != home)
				{
					bk.enabled = true;
					nextbtn.enabled = true;
					
					if(target == "bk")
					{
						historyStateCountBack--;
					}
					else
					{
						historyStateCountBack++;
					}
			
					bk.addEventListener(MouseEvent.CLICK,historyFunctions[historyStateCountBack-1]);
					
					if(historyFunctions[historyStateCountBack+1])
					{
						nextbtn.addEventListener(MouseEvent.CLICK,historyFunctions[historyStateCountBack+1]);
					}
				}
				else
				{
					//came from parent
					resetBack();
					nextbtn.addEventListener(MouseEvent.CLICK,historyFunctions[historyStateCountBack+1]);
					
				}
			}
			else
			{
				historyStateCountBack++;
				historyFunctions[historyStateCountBack] = funcName;
		
				bk.enabled = true;
				bk.addEventListener(MouseEvent.CLICK,historyFunctions[historyStateCountBack-1]);
			}
		
 
}

Open in new window

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question