Stupid Quick Question

What is the code I would use to tell a button (instance) to go a scene in a movie?

I was thinking:

officebut.onPress = function () {
gotoAndPlay(“Scene Office Movie, 1”);

but it didn’t work.


One word: _root.

pom :asian:

officebut.onPress = function () {
gotoAndPlay(“Office Movie, _root”);

Augh that didn’t fix it, so guess I didn’t put “_root” in the right spot eh?


No you didn’t :stuck_out_tongue:

You have to wonder, Vixie, who you are telling to gotoAndPlay, and from where (riddle #1).

pom :asian:

officebut.onPress = function () {
gotoAndPlay(“Office Movie”, _root);

(fixed a quote issue I think)

Okay to me that code says that I am telling the instance officebut (which happens to be my button) to go and play the scene Office Movie on the root level.

Am I missing it?

Vixie … who is really trying to learn :slight_smile:

officebut.onPress = function () {
gotoAndPlay(“Office Movie”, _root);

But wouldn’t “Office Movie” be a label? How do you tell it is a scene verses a label?

Oh now I am so confused.

Vixie … who knows this can’t be THAT complicated

OK, OK. To tell the _root to play, all you have to do is put _root. in front of your action. It’s called the dot syntax. You have to tell _root to play because you’re in the button (although it doesn’t really make sense, but I don’t know how buttons work exactly:)

_root.gotoAndPlay(“your Scene”,1);

When it’s a label, you don’t put a frame number afterwards.

pom :asian:

Are you applying the AS to a button or to an MC (movie clip)?

Button (insert on Button Actions)

on (press) {

MC (Insert in Frame Actions)

_root.officebut.onPress = function() {

I think that is how it would go. I am new too, so if I am wrong, sorry.

lol … thats why i have never messed with scenes … if my file is too big to do on one timeline then i make a new .swf file and link the two together. LoadMovie seems to work better for me :slight_smile:

but if you are trying to load the scene
the following code should work

on (press) {
gotoAndPlay (“Office Movie”, 1);

where Office Movie is the name of the scene and 1 is the frame in the scene that you wish to play on press of the button to which you have attatched this action; in your case officebut.

hope this helps :slight_smile:

the _root discussion was funny … thx for the laughs … i don’t use _root often though and my movies usually work … except when in cases of object control STUPID VARIABLE MATH!!!

>> lostinbeta: it works. buttons and clips can have dynamic handlers (otherwise, there’s no point giving them names…). And I think that Macromedia kept buttons only for backward compatibility, because they’re really useless now…

>> Shuga: Glad it made you laugh, but it wasn’t intented. I was in my ‘Spiritual guide’ break. And you’re right, scenes suck. But what you point out is interesting.

on (press) {
gotoAndPlay ("Office Movie", 1);

will work, but not

officebut.onPress = function() {
	gotoAndPlay("Office Movie", 1);

won’t. Which means that putting a dynamic event handler makes the code inside it relative to the object. Which is not true for a movie clip.

I’ll have to check on that.

pom :asian:

Very edumactional :slight_smile:

(Yes that was intentionally mispelled, I am not THAT stupid)

pom … i don’t understand the purpose of the

= function() {

can you please explain why one would put that in there instead of just the simple gotoandPlay code?

also about the _root thing:
_root is very useful when you are specifying an action on a symbol deep within your movie so you don’t have to back out of directories (i.e. …/…/…/…/instanceName) instead you can just put _root.instanceName b/c when you are specifying an action for an instance that is in the _root already … its a bit redundant to tell the computer _root

I know you can add parameters in between the () in your funtion.

Does that serve the same purpose it does in javascript?

In javascript it would look like this (taken from an earlier img rollover script I wrote)

function imgOn (imgName) {

blah blah blah

then in your link for you rollover it would be
A HREF="#" onMouseover=“imgOn(imgNameforRollover)”

then when you mouseover the image with the link it will change it to the new image.

The new image was called imgNameforRollover and in the script it is specified as

imgNameforRollover = mynewimage.jpg

so it would replace old.jpg with mynewimage.jpg

Just wondering if its the same purpose.

(if you don’t understand the javascript thing, sorry, I hate explaining things…lol, i’m not very good at it)

Aha!! You’ve not read my last tute! I’ll tell Kirupa.

Check the dynamic event handlers.

pom :asian:

officebut.onPress = function() {
gotoAndPlay(“Office Movie”, 1);

Works but it doesn’t. See it loads a scene, but it is the next scene I have not neccessarily (sp?) the scene named.

So we are getting close :slight_smile:


_root., Vixie, _root… (read the posts once more :stuck_out_tongue: )
And I’m going to bed, so i hope you’ll make it this time.

pom :asian:

Added _root and it works :slight_smile:

Weird because I did that before and it didn’t have any effect, but this time it did.


Ah well as long as it is working, I am a happy little camper,
Vixie … who thanks you’al for helping=)

Hey lyaslamasse,

I actually didn’t read your tutorial until now, and it explains it GREAT! Im glad you posted that link. I will be checking out all those AS Tricks.

You really are a flash guru!!!

Hey Vixie,

Congrats on getting your button to work!

aye lad … lyaslamasse is da bomb flasher !!