Solved

Goto and play command not working on button in dragable movie clip.

Posted on 2004-09-16
24
4,413 Views
Last Modified: 2008-01-09
Can you help guys?

I am using Flash MX, ver 6

 

I have a nav bar with a hole on it (the hole being on its own layer and a movie clip, called hole)

I have a ball, on its own layer, and can be moved around, as a dragable movieclip

 

The code below allows the user to drag the ball over the hole.

When it does the ball disappears, but the last line of code gotoAndPlay("Scene 2", 1);

Doesn’t work.

When I release the ball over the hole it disappears but flash doesn’t go to scene 2

(I have stop actions on both scenes) to stop them looping

What is wrong with the code? I have noticed in my version of flash that the goto and play scene (whatever scene) works when the action has been applied to a button movie clip, but not a normal movie clip instance?

Maybe it is not working because the goto action has been applied to a dragable movie clip, and not a button movie clip? Although when I edit the dragable movie aren't I applying the code to the button in the movie anyway?

 

Also I want the button to nav to other scenes when I put it in other (movie clip holes), will it just be a case of replicating the code from “on (release) { if (get property” etc and changing the drop targets and scenes?

 

on (press) {

    startDrag("button");

}

on (release) {

    stopDrag();

}

on (release) {

    if (getProperty("button", _droptarget) eq "hole") {

    }

    setProperty("", _alpha, "0");

    gotoAndPlay("Scene 2", 1);

}
0
Comment
Question by:Gazzbut
  • 14
  • 6
  • 2
  • +2
24 Comments
 
LVL 10

Expert Comment

by:muso120999
ID: 12072687
Might be a scope thing:
   gotoAndPlay("Scene 2", 1);

only works from _root (the main timeline).

I would suggest labelling your frams in scene 2, and using

_root.gotoAndPlay("Scene2_Label");
0
 
LVL 7

Expert Comment

by:ssdesign
ID: 12072697
Ahy you need to have 2 on (release) codes? try this:

on (release) {
    stopDrag();
    if (getProperty("button", _droptarget) eq "hole") {

    }

    setProperty("", _alpha, "0");

    _root.gotoAndPlay("Scene 2", 1);

}
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12072729
Here's my suggestion for Flash MX AS1
//getproperty and drop target are obsolete.

on (press) {
 startDrag("button");

}

on (release) {

    stopDrag();

}



    if (getProperty("button", _droptarget) eq "hole") {

    }

    setProperty("", _alpha, "0");

    gotoAndPlay("Scene 2", 1);

}
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12072772
oops sorry, ignore first post code, pressed <enter> by mistake.

try this.

instead of attaching code directly to the button, put this code on the button("button"):
on (press) {
      _root.drag(this);
}
on (release) {
      _root.drop(this, "_root.hole");
}
then on the main timeline, in the first frame of scene 1, put this code:
stop();
function drag(what) {
      startDrag(what);
}
function drop(what, target) {
      stopDrag();
      if (what.hitTest(target)) {
            what._visible = false;
            gotoAndStop("Scene 2", 1);
      }
}

and thats all.
a better way to go about it, me thinks.
blu.
0
 

Author Comment

by:Gazzbut
ID: 12076219
Have enter this code but flash doesn’t send me to scene 2.

What is wrong?

 

 

on (press) {

    startDrag("button");

}

on (release) {

    stopDrag();

    if (getProperty("button", _droptarget) eq "hole") {

    }

    _root.gotoAndPlay("Scene2", 1);

}
0
 

Author Comment

by:Gazzbut
ID: 12076237
to blue genie - I dont understand how to add the actual button. Button is in movice clip called place but when i double click on button and get the different key frame states I cant add actions to it. Do i need to go up a level?

Thanks!
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12081862
i'm not sure i understand your problem?

whereever you have the on (press) and on(release) now - just replace it with what i'm telling you to do.

you're not changing anything, except your code.
0
 

Author Comment

by:Gazzbut
ID: 12083013
Blue genie - this worked for the first button to make it go to the second scene. I have got three other buttons on scene on to go to various other scenes, i copied the code on the button and changed it to root.hole2   (the name of the second button) then on  a new layer on scene 2 copied the action but changed goto scene 3 and stop. When I tried this the same button went to scene 2
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12083060
ok, simply change the function then to this

function drop(what, target, whichScene) {
     stopDrag();
     if (what.hitTest(target)) {
          what._visible = false;
          gotoAndStop(whichScene, 1);
     }
}
0
 
LVL 7

Expert Comment

by:ssdesign
ID: 12084378
ok if the button is inside the movie clip, then you can try a crude method.

In the main timeline, create a LABEL on a frame and call is "goNextScene". ON this very keyframe, write an action to go to Scene2: gotoAndStop("Scene2");

Then go to the button inside the movie clip and give a action to

_root.gotoAndPlay("goNextScene")
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12084523
don't be crude , the function works a charm .
0
 

Author Comment

by:Gazzbut
ID: 12085560
Hi Genie, sorry but I’m just not getting this! Doh!

 

Let me tell you what I’ve done and what I’ve got so far and you can tell me where I’m going wrong. Might need it to be explained a bit in detail I’m afraid.

 

OK in scene one I have six layers. Layer 1, my background j-peg image (the size of the stage), layer two the hole which movie clip hole one sits on, layer three where hole 2 sits on.

Layer four, the layer that has the draggable movie clip button in it, and the final two layers the actions layers for each hole movie clip.

 

On the button(button) in the draggble movie I have put the following

 

on (press) {

    _root.drag(this);

}

on (release) {

    _root.drop(this,"_root.hole1");

    _root.drop(this,"_root.hole2");

}

 

I thought this would make both holes active targets? Am I wrong?

 

In scene one I have the two action layers for each hole movie clip like I said

On one layer I have the actions for hole1:

 

  stop();

function drag(what) {

    startDrag(what);

}

function drop(what, target) {

    stopDrag();

    if (what.hitTest(target)) {

        what._visible = false;

        gotoAndStop("Scene 2", 1);

    }

}

 

On another layer in scene 1 I have this actions for hole2

 

stop();

function drag(what) {

    startDrag(what);

}

function drop(what,target,whichScene) {

    stopDrag();

    if (what.hitTest(target)) {

        what._visible = false;

        gotoAndStop("Scene 3", 1);

    }

}

 

Hole 2 just goes to scene 1, like hole 1 does?

What do I change to the actions layers and scrip to the button in the dragable movie clip so when the button goes over different holes in scene 1 they will take the user to other scenes??

 

Much appreciated if you can explain it

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 39

Expert Comment

by:blue-genie
ID: 12099933
no dude!!! what are you doing? (just kidding)

ok. let me explain it this way.
the function is a generic function. you do not need to replicate it all the time. you declare your function once, and call it from where ever you want, when you want to access it.

first of all, why are you having 2 hittests? as in:
on (release) {

    _root.drop(this,"_root.hole1");

    _root.drop(this,"_root.hole2");

}

secondly, your function must go onto any 1 of your actionscript layers, ONLY ONCE.
and don't change anything just copy and paste it from here.
//this function accepts 3 variables, what's being dropped, what is its hittest, and what is the target scene.
function drop(what, target, whichScene) {
//standard stopdrag
     stopDrag();
//check if it has hit the right target that you specify on the button *NOT HERE
     if (what.hitTest(target)) {
          what._visible = false;
          gotoAndStop(whichScene, 1);//go to whichever scene as specified.
     }
}

then, on each of your buttons.

let say button1, must be dropped on target 1 and then go to scene 1.
so button 1 will say.

on (release) {
_root.drop(this, "target1", "scene1");
}

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12100103
sorry, was in a hurry to post as i had to reboot,
but basically then, continuing from 1st post,

button 2 wil look like this (without changing the function in the actionscript layer)

on (release) {
_root.drop(this,"target2", "scene2");
}

 and so on....

hope this makes sense.

blu.
0
 

Author Comment

by:Gazzbut
ID: 12113633
Hi blue have tried to do what you have asked but have hit two snags…one, when I try to paste the function you gave me in the action layer in scene 1 (which you say I only do once and don’t change), it states it contains an error…

It asks me to state an actual scene in the last line of code instead of just having goto and stop (which scene, 1)

It wants an actual scene “     “

 

Secondly when I stop dragging the button it automatically goes to scene 2, before I put it over the target…

 

This is the code I have  put on the button, like you said (bearing in mind my testtarget is called hole1)

 

 

on (press) {

    _root.drag(this);

}

on (release) {

    _root.drop(this,"hole1","scene2");

}

 

 

Then in the action layer on scene one I put this…as you can see in the last line of code it has (“scene2”, 1) instead of what you had……. goto and stop(whichscene,1)

 

Flash states I need to put an actual scene.

 

stop();

function drag(what) {

    startDrag(what);

}

function drop(what, target, whichScene) {

    stopDrag();

    if (what.hitTest(target)) {

        what._visible = false;

    }

    gotoAndPlay("Scene 2", 1);

}

 

Sorry to be a pain!!

 

0
 
LVL 1

Expert Comment

by:billyvandergaw
ID: 12114124
have you tried reversing the layers?  just one or the other ontop of the other and see if it works.
It's a dumb thing to say, but dumb solutions are the simplest answers
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12120435
Gazz, i don't know what you're doing.

can u upload ur file?
0
 

Author Comment

by:Gazzbut
ID: 12120574
Can I email it to you? or if not I will upload it onto some webspace tommorow

Thanks for all you help!
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12120878
blue-genie at bigfoot.com

Note to administrators - I'll post the results back up.

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12121747
Gazz, i'm stumped.
sorry i misunderstood u, i thought you had multiple draggable buttons.

hmmm. a lot of ppl have been having problems with this gotoAndPlay Scene thingie. I stand by my convictions that scenes suck!!

i'll keep trying, but i suggest you lose the scenes.
you're better off using swfs and loading them as required.

blu.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12121778
something interesting (actionscript.org)

"So you see, Movieclip.gotoAndPlay does NOT have a scene parameter. Hence, if you are inside a movieclip and trying to reach the first frame in Scene 1, using _root.gotoAndPlay("Scene 1", 1) just won't work. It's essential to understand that scenes are not exported in the swf. All scenes are put one after the other to create a single scene when publishing to swf, much like layers. If you use gotoAndPlay with the scene parameter, when you publish your file, the IDE compiler will catch these calls and converts them to standard gotoAndPlay calls without the scene parameter.

For example, if you have two scenes called Scene 1 and 2, both having 10 frames, and you use gotoAndPlay("Scene 2", 5), the compiler simply translates it to gotoAndPlay(15). If you want to use that call inside of a movieclip, simply use _root.gotoAndPlay(15). This goes for gotoAndStop as well. You may also use frame labels, as they also work well."
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12122383
No dude, my point is try and avoid using scenes altogether,
the example i was first referring to was if this hits the hole, then go to this scene (specifying the scene).
so my advice is using loadMovie and swfs (go see link below).
http://www.geocities.com/bluegenie_sa/ee/tacyon1_new.html

you can grab the source out of
http://www.geocities.com/bluegenie_sa/ee/scenes.zip

if you were to compile it properly, instead of loading the scenes in root, you'd have your navigation in an upper level, that way you don't need to duplicate it, and it persists throughout.

0
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 12124158
Gazzbut says:

"Thanks for the files and info. You're a star.

I take it, now all I do now is, save/ make all my swf movies a scene name i.e. scene,2swf,scene3swf as you have done."

<Blu>yes, instead of creating scenes, create each in its own fla and swf.

Just one question, how do I set them all up, i.e. I'm going to put them into dreamweaver. Do I just place the main file, tachyon new swf in  a html page, and put the other swf files into the site folder, or do I have to put each scene swf on a separate htm page in the site?"

<Blu>the first swf will be embedded in html, the rest will be loaded from the path you specify.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 12286463
i'd load them on request, ie don't embed them all in html.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now