|
From: kirkdizzle on 18 Apr 2008 06:28 I am making a flash document to embed in a dreamweaver site and I do not know how to give action to a button I have created. I am hoping somebody might be able to help me?
From: rritchey on 18 Apr 2008 09:44 If you are using Actionscript 2 then : With the button selected open the Actions panel. Type the following for a button release script: on(release){ //do my actions here trace("You clicked the button"); } for a rollOver action: on(rollOver){ //do actions here trace("you rolled over the button"); } etc...
From: rritchey on 18 Apr 2008 09:48 If you are using Actionscript 3 then: Give the button an instance name. To do this: 1. Select the button on the stage 2. Go to the properties panel and enter some text (IE "myBTN") into the box under the "Type" drop-down. Next, select the frame on your timeline and go to the actions panel. Enter the following code. (This works if the button is called myBTN): myBTN.addEventListener(MouseEvent.CLICK,doClick); function doClick(evt:MouseEvent):void { //do actions here trace("You clicked the button"); }
From: Rothrock on 18 Apr 2008 10:17 If you are new and using AS2, then rritchey's advice will work, but I don't think it is the best way to go about this. The on(event) handlers way of coding was developed for Flash 5 and went out of favor with Flash 6 which introduced frame code for events and made life much much better. Here is a good tutorial about the switch and why it is better: http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent So instead of putting the code directly on the clip, you give the clip an instance name (using the properties panel) and then use a script on the frame (make sure you have a frame selected and not the clip! the actionscript panel will say frame at the top if you've done it right) and then enter this code: myClip.onRelease=function()[ // actions you want here trace("you clicked the button"); } myClip.onRollOver=function(){ //actions you want here trace("you clicked the button"); } In this case I'm imagining that there is a movieclip instance on the stage at that frame -- it could be on a different layer and have started in a different frame or continue on into additional frames, but it must exist at least AT that frame -- with and instance name of "myClip". Remember that it isn't the name you give a clip in the library, that is just to help you when you are looking through the library. It is the name you give the instance when you drag the clip onto the stage. The best thing about frame code (at least for me) is that it is all in one place. So if you have 5 clips on one frame you can see all the code in one spot, you don't have to select each clip to view the code. And it is a lot easier to maintain the code if you want to change it later.
From: Amit Kaushal on 18 Apr 2008 10:57 Create an instance for your button say if you are creating a site and there is a home button then select the button open the properties panel , in the instance name type home_btn , remember this name is to be used in action script , then in timeline select the frame and open the actions panel by pressing f9. home_btn.onRelease=function(){ //any action you want , say you want to navigate to your homepage getURL("url of your homepage", window, target); }
|
Next
|
Last
Pages: 1 2 Prev: Developing Engine in Flash Next: Stop a nested movie clip from main timeline |