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:
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):Code:on(release) { gotoAndPlay("Scene", 1); }
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.")Code:stop(); myBtn_btn.onRelease = function () { gotoAndPlay("frameLabel");} ; === or === this.stop_mc.onRelease = function () { stop(); }; === or === _root.onEnterFrame = function () { ... }
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:
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).Code:home_btn.addEventListener(MouseEvent.CLICK, goHome); function goHome (myEvt:MouseEvent): void { navigateToURL (new URLRequest("http://www.auntnini.com"));}
Your code might look like:
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.Code:this.happy_btn.addEventListener(MouseEvent.CLICK, goSmile); function goSmile (e:MouseEvent) void { gotoAndPlay("smile"); }
=======================
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.
Last edited by auntnini; 02-14-2010 at 11:00 PM. Reason: p.s. re actions layer
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( i really suck at as)
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
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.Code:stop(): this.my_btn.onRelease = function () { gotoAndStop("labelName");}
Last edited by auntnini; 03-03-2010 at 01:38 AM. Reason: emphasis
You might re-submit a FLASH query and just concentrate on the button action.
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.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?
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 .
Last edited by auntnini; 03-05-2010 at 03:54 AM. Reason: spellling"test"
Mopia (03-05-2010)
I wanted to attach these too.
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
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.
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).
Bookmarks