Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : as2.0 class event handler code not accepted


xyz123
5/25/2004 11:08:11 PM
Hello,

In my search to redefine attachement behaviour for movie clips using a new
class definition for a Symbol1 movieclip(library), I run into a strange error.
If anyone can tell me what is wrong.....?

The following code just works right......if I do uncomment the
onClipEvent(mouseMove) method I do get error messages as shown after the
program code. I find this strange ...why can I use/define on(..) event handers
here without any problem but do I get suddenly a lot of errom essages asking
for names when using a plane old onCLipEvent(mouseMove) event handler.

Thanks a lot


=========================


class Symbol1 extends MovieClip{
var xPos:Number=0.0;
var yPos:Number=0.0;


function Symbol1(){
trace("just created a Symbol1 type instance");
}
function attachLibSymbol(lib_mc:String, inst_mc:String, level:Number ){
//this.attachMovie(lib_mc,inst_mc, level);

trace("attachLibSymbol(lib_mc:String, inst_mc:String, level:Number )
"+lib_mc);
}
function attachInstance(mc:MovieClip){
//this.attachMovie(lib_mc,inst_mc, level);
trace("just attached movie instance "+mc);
}
/*
function onClipEvent (mouseMove) {
trace("mouse moved");
}
*/


function onPress() {
startDrag(this);
}
function onRelease(){
stopDrag();
}
}

error messages when uncommented mouseMove eventHandler:

**Error** C:\Flash\Symbol1.as: Line 19: Function name expected
function onClipEvent (mouseMove) {

**Error** C:\Flash\Symbol1.as: Line 1: Statement block must be terminated by
'}'
class Symbol1 extends MovieClip{

**Error** C:\Flash\Symbol1.as: Line 31: Syntax error.
}

**Error** C:\Flash\Symbol1.as: Line 19: All member functions need to have
names.
function onClipEvent (mouseMove) {

Total ActionScript Errors: 4 Reported Errors: 4


xyz123
5/26/2004 12:52:18 PM
The first option, MovieClip.onMouseMove(), works perfectly!

I now see that onClipEvent is actualy not a MovieClip event but basically a
movieEvent. Problem is why then does it work when I put the code on an instance
directly....hummm maybe an idea for a new topic: what is the difference between
a movieEvent and a movieClipEvent?

thanks!


Timothée_Groleau
5/26/2004 1:43:25 PM
Try

function onMouseMove() {
trace("mouse moved");
}

I can't remember whether onMouseMove is a default handler in Flash
MX2004. If it's not working, you may need to register your clip as a
listener to the mouse. In the contructor, you would add:

Mouse.addListener(this);

That should do (though I haven't tested).

Timothée_Groleau
6/9/2004 11:23:29 AM
[quoted text, click to view]

onClipEvents are a legacy of the flash 5 days. The events are set on a
movieclip instance directly and cannot be changed at run time.

the onSomething event handlers (onRelease, onMouseDown, etc.) were
introduced in Flash MX new event model, you can change the handler at
run time. It gives a lot greater flexibility in run-time and also helps
in code design because 1) it fosters clearer separation between code and
graphical elements and 2) it allows you to centralize your code in a
single place as opposed to scatter it on many different movieclips
AddThis Social Bookmark Button