?
Solved

is the a script to create a back button

Posted on 2004-11-17
19
Medium Priority
?
210 Views
Last Modified: 2008-02-01
hi
is there a script to acheive the following

when a button is clicked the user is sent back to the scene they arrived from
this is not necessarily the prevScene

thanks in advance
liseperu
0
Comment
Question by:liseperu
  • 10
  • 7
  • 2
19 Comments
 
LVL 8

Expert Comment

by:sokhodom
ID: 12606775
Do you mean this:
attach this action to the button:

on(release) {
      gotoAndPlay("Scene 3",1);
}

Where Scene 3 is just a name of your scene.
Or you mean like " we dont know which scene the user come from" and we want to detect where he comes from and then go to that scene?

0
 

Author Comment

by:liseperu
ID: 12606823
the latter
i want to detect where they came from
and send back when the button is pressed - if poss

thanks
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 12607238
Hi, if you want the later one you should implement the flash version of COokies call SharedObject. Okay, i've test out and it work. You can view it here:
http://www.ntu.edu.sg/home2001/n0069866/scence.swf and http://www.ntu.edu.sg/home2001/n0069866/scence.fla

Here i have 4 scence. To test it, you click on the button on the first scence. it will let you to scence 3. In scence 3, i have 2 buttons, one for go back to previous scene i.e scene 1 and the other one is to go somewhere else , in this case scence 4.
So all in all, scence 2 was not into play.

Alittle note one shareobject. ShareObject inside flash is similare to implementing cookie. waht is does is to remember the user data. We can use ShareObject such as when user fill in the form etc.. You can view the tutorial here as well : http://www.kirupa.com/developer/actionscript/shared_objects.htm.

Cheers :)
SokhodoM
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 39

Expert Comment

by:blue-genie
ID: 12612045
a quick and nasty solution

when u navigate (ie. click next ) - add that scene i.e current scene to an array, then when you click the back button, check which is second last item in array - and navigate there.

blu.
0
 

Author Comment

by:liseperu
ID: 12612639
hi
i likes blus thinking will give it a go and let you know
thanks
0
 

Author Comment

by:liseperu
ID: 12612668
do you knwo the code to capture the current scene?
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12612750
when you press next, you're telling it to go to a particular scene right?

so put that in as you're going there. that would be the easiest way.
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 12612857
to capture the current scene, you also can use ShareObject.
You place the shareobject variables "which also include the scence variable" in each scene and when u want to check which scence you came from just retrieve that variable..
Ya.. what i like about Flash is that it has many way to move around the problem.. haha..
Cheers :)
SokhodoM
0
 

Author Comment

by:liseperu
ID: 12612963
hi sokho
i get it now
will give it a go and let you know how i get on
thanks
liseperu
0
 

Author Comment

by:liseperu
ID: 12613276
ok

the button i have created is storing the correct values but is not going to the scene when click

i have three bits of code

//global code in an include file
user = SharedObject.getLocal("visit");
user.data.name = "visited";
var backbutton:Array = [];
bbpos =0; //back button position counter

//the code that is intiated on the first frame of the scene
//code to store data for back buttons
user.data.scene = "Scene 2"
//put the current scene on the array
backbutton.push([user.data.scene]);
//increment the array back button position
bbpos++;
trace(bbpos);

// the code that is called when the button is pressed
on (release) {
      if (user.data.name == "visited")
      {
      bbpos--;
      trace(bbpos);
      trace(backbutton[bbpos]);
      gotoAndStop("backbutton[bbpos]",1);
      }
}

--------------------------------------------------------------

the output window indicates that when the button is pressed all the data that should be there is there

------->out put window<------------
0               //array position
Scene 1     //data in array at that position
------->------------------<------------

but the scene doesnt change and the array then becomes silly with negative nmbers and undefined variables

any ideas?

liseperu
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 12613636
May i know where you put your include files?
0
 

Author Comment

by:liseperu
ID: 12613683
the include file goes on the first frame of the first scene
the back button is used on the second scene
and will be used on all scenes excpet the first when i get it working

thanks
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 12613852
wa... I've figuere out... (on my pc) :)

Try this,
instead of gotoAndStop(...) put gotoAndPlay(); for example:
// the code that is called when the button is pressed
on (release) {
     if (user.data.name == "visited")
     {
     bbpos--;
     trace(bbpos);
     trace(backbutton[bbpos]);
     gotoAndPlay("backbutton[bbpos]",1);   ////////// here is what needed to be changed... try..:)
     }
}
cheers.
SokhodoM
0
 

Author Comment

by:liseperu
ID: 12616518
ok
this is driving me mad
yours works mine doesnt
i have now basically copied all your code over mine
taken it out of the actionscript includes

and i have tested that a noremal gotoAndPlay works - which it does

i almost out of ideas
and and randonly just changing things round to see if anything works

nothing seems to be working
even though the output wind is displaying all the expected data
:(
liseperu

0
 

Author Comment

by:liseperu
ID: 12616709
the output window is below

the first scene is Scene 1
the position of the array is 0
_______________________
posistion of array is    1
this is    Scene 2
________
now the position of array is 0
The scene to be played is Scene 1
___________
posistion of array is    1
this is    Scene 2
________

>>>>>>>>>>>>>>>>>>>>>>>>>>>
as you can see it is getting all the correct data
only it is not moving going to the scene
instead it reloads the current page

any ideas?
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 12616863
liseperu, I wonder if you could share that part of your .fla so that i could take a look?
In fact, it works in mine..
0
 

Author Comment

by:liseperu
ID: 12616927
sure
this is my email liseperu@netscape.net
if you send me a blankie i will reply with the fla attached (500k)
thanks
0
 
LVL 8

Accepted Solution

by:
sokhodom earned 800 total points
ID: 12619863
Hi there,
Ya the solution is like this:


1- Put this inside your backbutton except backbutton on first Scene

on (release) {
      if (user.data.name == "visited") {

      _root.gotoAndStop(backbutton[bbpos-2]);          
}
Notes here that it's minus 2 instead of bbpos and i didn't implement the bbpos--. My reason is that i will add ALL the Scene Frame name to the Array and will call the last two element. it's two element, bcoz i've implement the bbpos++ in the main frame. see section 3 and 4.

2. Put this on First Scene:
on (release) {
      if (user.data.name == "visited") {

            _root.gotoAndStop(backbutton[bbpos-1]);
      }
}
Note that here is minus one.
3. On first Scene on separate frame type this:

user = SharedObject.getLocal("visit");
user.data.name = "visited";
var backbutton = [];
bbpos = 0;

user.data.scene = "Scene 1";
backbutton.push([user.data.scene]);
bbpos++;

Note that it's bbpos++ AFTER inserting the element to array
4. On First FRame of OTHER scence put this on separate frame:

user.data.scene = "Scene 2";   <--- change the Scene 2 to other frame name.
backbutton.push([user.data.scene]);

bbpos++;

Note here that bbpos++ is after inserting element to array.
Okay, here you would know why i put bbpos-2 instead of bbpos-1 mention in number 2.
5. Finally test and run. It should be okay.

Cheers :)
SokhodoM
0
 

Author Comment

by:liseperu
ID: 12620139
thank you mate
i have increased the points
as i was 110% happy with the answer and the time it took to help

cheers
liseperu
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
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…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

839 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