View Full Version : When clicking button in movie clip to play frame in scene1
Mopia
02-12-2010, 05:13 PM
Hi, confusing thread title i know but i dont know how else to put it.
I have a movieclip, inside that movieclip is a button. when someone presses that button i want it to go to a frame label called "over" in scene1. i have no idea how to do this, any ideas?
http://img710.imageshack.us/img710/4215/movieclip.jpg (http://img710.imageshack.us/i/movieclip.jpg/)
auntnini
02-14-2010, 10:51 PM
Once upon a time, not so long ago (but several Flash versions past), you could select a button instance on Stage and directly attach an event handler and action to it:
on(release) { gotoAndPlay("Scene", 1); }
Then, circa 2003 version MX or so, came ActionScript 2.0 with dot.syntax, data:typing, and notion of using anonymous functions in the Timeline (for which you need a keyframe selected in Timeline to open Actions panel):
stop();
myBtn_btn.onRelease = function () { gotoAndPlay("frameLabel");} ;
=== or ===
this.stop_mc.onRelease = function () { stop(); };
=== or ===
_root.onEnterFrame = function () { ... }
At some point (don't recall when or why), you no longer needed to enclose a Button symbol inside a MovieClip symbol to use mouse event handlers such as onPress, onRelease, etc. (I cannot find a quick reference about "buttonMode=True.")
Enter the hard-core OOPy API (Object Oriented Programming / Application Program Interface) gang's ActionScript 3.0 a while back (with what, CS2 version?) to turn things upside down. ActionScript 2.0 and 3.0 are not compatible so, right up front when you first create your FLA, you have to decide which path to follow. And you also have to File>Save As to designate a lower version.
For example in AS 2.0, you could use: getURL("http://www.auntnini.com");
AS 3.0 would require something like:
home_btn.addEventListener(MouseEvent.CLICK, goHome);
function goHome (myEvt:MouseEvent): void {
navigateToURL (new URLRequest("http://www.auntnini.com"));}
AS 3.0 FLA files are associated with new document class, and automatically generated default called MainTimeline extends MovieClip class (a DisplayObjectContasiner). Object must have an instance name and "subscribe to" ____.addEventListener(event.TYPE, function). If instance name has _mc, _btn, etc. suffix, a list of possible properties and methods display when you type the .dot (as in dot.synatx).
Your code might look like:
this.happy_btn.addEventListener(MouseEvent.CLICK, goSmile);
function goSmile (e:MouseEvent) void { gotoAndPlay("smile"); }
Now, don't quote [unless to correct] me because I'm finding it difficult to locate comprehensive CS4/AS3.0 sources of information and probably have a lot of this wrong. But, hopefully, my response will get the ball rolling so you get the assistance you requested.
=======================
P.S.: Whether AS 2.0 or As 3.0, create a layer at top of layer stack (called. what else, "actions") and insert a keyframe where you want to enter actions. Select the keyframe in Timeline to open Actions panel in which you enter your code.
Mopia
03-02-2010, 05:14 PM
Man this is so difficult for something so simple... it doesn't work , probably my fault. im using as 2.0 btw . can you tell me what the name is of the stage? is it _root?
Thank you for your time and effort already, must have taken ages to type :D ( i really suck at as)
auntnini
03-03-2010, 01:33 AM
I suggest you try to submit a copy of your code so someone else can look at it. I was just trying to copy something from Movie Explorer in FLASH, but I cannot seem to paste it. I'm on a PC right now, could have captured a screen shot on MAC {Cmd-Shift-4 or -3).
I think ActionScript 2.0 is the way to go if you do not need to get OOPy. Just be sure you make that choice when creating a new doc. With AS 2.0 you can even attach script to object on Stage (like AS 1.0).
In frame 1 keyframe on Actions layer, I put
stop():
this.my_btn.onRelease = function () {
gotoAndStop("labelName");}
In frame 25 I also had keyframe for action: stop(); this refers to current Timelilne. _root referred to Main Timeline. Don't think you need to refere to "Stage". Drag instance of symbol onto Stage and give it a name (e.g., my_btn) so you can talk to it.
auntnini
03-05-2010, 02:59 AM
You might re-submit a FLASH query and just concentrate on the button action.
I have a movieclip, inside that movieclip is a button. when someone presses that button i want it to go to a frame label called "over" in scene1. i have no idea how to do this, any ideas?
Forgive me for fumbling, forgetting and/or getting too basic. But why do you have a button in a MovieClip? Back then, we'd put an "invisible button" (just the HIT state) over a MovieClip so we could use on(press) on(release) MouseEvents to startDrag() / stopDrag() and such. Since MovieClip symbols only require one keyframe on a Timeline to play, it would seem more logical to place a MovieClip instance in a button keyframe to animate a state (most probably OVER or DOWN). Remember, you need the HIT state for user interface.
Drag an instance of the button symbol to the Stage, and give it a name in the Properties panel so you can talk to it with ActionScript. In a keyframe in a layer at top of layer stack (for Actions), Window>Actions or F9 (Option-F9 MAC) to open Actions panel and enter your ActionScript commands/statements. You can click the cross-hair in a circle button ("insert a target path") and it will list symbol instances with names; click the instance and Flash will enter something like: this You enter the event handler (e.g., onRelease) = function () { gotoAndStop("frameLabel"); }
Here are some screen shots of a simple AS 2.0 FLA test .
auntnini
03-05-2010, 03:01 AM
I wanted to attach these too.
Mopia
03-05-2010, 03:28 PM
I suggest you try to submit a copy of your code so someone else can look at it. I was just trying to copy something from Movie Explorer in FLASH, but I cannot seem to paste it. I'm on a PC right now, could have captured a screen shot on MAC {Cmd-Shift-4 or -3).
I think ActionScript 2.0 is the way to go if you do not need to get OOPy. Just be sure you make that choice when creating a new doc. With AS 2.0 you can even attach script to object on Stage (like AS 1.0).
In frame 1 keyframe on Actions layer, I put
stop():
this.my_btn.onRelease = function () {
gotoAndStop("labelName");}
In frame 25 I also had keyframe for action: stop(); this refers to current Timelilne. _root referred to Main Timeline. Don't think you need to refere to "Stage". Drag instance of symbol onto Stage and give it a name (e.g., my_btn) so you can talk to it.
Is it all right if i upload my fla? that'd be better i suppose! its made in flash 8 as 2.0
http://www.megaupload.com/?d=HHOOPHW9
it's the button to the left on the stage, the black square. the starts at frame 8. if you could look at it i would appreciate it alot man
auntnini
03-05-2010, 10:55 PM
Interesting. I did not know you could do that. But I failed to open the FLA on the Flash CS4 I'm using. Maybe I did something wrong. Anyhow, why don't you re-post a FLASH query (unless someone comes to our rescue here) with that FLA upload link?
Good luck.
Mopia
03-08-2010, 02:56 PM
Interesting. I did not know you could do that. But I failed to open the FLA on the Flash CS4 I'm using. Maybe I did something wrong. Anyhow, why don't you re-post a FLASH query (unless someone comes to our rescue here) with that FLA upload link?
Good luck.
Thank you for all your effort, i have found the solution . it was this:
on (press) {
_root.gotoAndPlay("over");
}
:D
auntnini
03-08-2010, 11:03 PM
Attaching code directly to object on Stage is what they designate as ActionScript 1.0 -- which AS 2.0 allows you to do because AS 1.0 and 2.0 are compatible. _root refers to the Timeline.
This seems the simplest approach. Glad it is woroking for you.
I think you should close up the space after on(press).
BLiZZaRD
03-11-2010, 01:28 AM
In the future, you will want to try to get away from the actual on button code.
Give you button (or MC) an instance name, then from the main timeline or a separate .as file, you will switch to something like this:
[code]
myBtn.onPress = function(){
this._parent.gotoAndPlay("over");
}
The correct syntax for "this._parent" will vary depending on where you place the MC/button. it could be this._parent._parent, or whatever...
best way to know.. find the cross hair icon in the actions pane. click it. Find the reference you want (the button, in this case) and click it once. The syntax will appear in the top of the window there.
Yes, you can use "_root" but remember, we are now on Flash 10, and 11 is coming. _root, is out as of AS3, and depreciated in AS2. Get used to not using it. it will break things in the future. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.