Groups | Blog | Home
all groups > flash actionscript > september 2007 >

flash actionscript : Button Problem!



kitster79
9/18/2007 7:13:09 PM
I have just upgraded to Flash CS3 and I'm having problems with attaching
Actionscript to just a button!:)

I'm probably just missing something really obvious but can anyone suggest why
it is not letting me?

Thanks

Kit
Ardy15jan
9/18/2007 8:17:44 PM
Well, AS3 doesn`t support attaching code to a MovieClip or Button directly on
an instance. So if you tryed to do that, it won`t work. You can only add
Actionscript to frames(at least that`s what I understood after checking out the
help documentation, Actionscript migration - [b]if I`m wrong, and anyone knows
if this is possible and how it`s done, please post[/b]).
There is a new system for event listening(check out the help menu). There`s no
more [i]MovieClip.onMouseDown = function(){}[/i], now event listening is done
by means of [i]addEventListener(<event type>, <event handler function>)[/i].
So, if you want to add some event handlers for a button, try the following code:



mcButton.addEventListener(MouseEvent.CLICK, onMouseDown);

function onMouseDown(event:MouseEvent):void {
// Here you place the code that runs when the button is pressed
}
kitster79
9/18/2007 8:48:00 PM
Manno Bult
9/18/2007 9:39:53 PM

AS3 deals with it more verbose, but more standard too. AS3 does not
allow attaching script to objects. Script can only be placed in the
timeline or in external script files.

Either use AS2 settings or take a look at eventhandlers and the
addEventListener() method in particular. (look for addEventlistener in
the helpfiles and the third item has a good example)

HTH,
Manno

[quoted text, click to view]


--
----------
Manno Bult
AddThis Social Bookmark Button