all groups > flash actionscript > february 2004 >
You're in the

flash actionscript

group:

Flash MX Event Model


Flash MX Event Model BarneyK
2/2/2004 5:04:42 PM
flash actionscript:
Good Evening,
I am just trying to get to grips with the Flash MX event based model after having always previously used Flash 5, but I have got stuck.

I have the following code that allows a user to click and drag on a movie clip and rotate it to a position they want. The code does rotate the mc as I want it to, but I need it to stop rotating the clip when the user releases the mouse button or moves away from the mc area. At the moment after they click the mouse the first time it continues to execute the code even after the mouse button is released.

Any help appreciated, it is probably something really simple to do with the new event based model.

origX=aboveCamera._x;
origY=aboveCamera._y;
this.aboveCamera.onMouseDown = function(){
onMouseMove(this.aboveCamera) = function(){
newX=this._xmouse -origX;
newY=this._ymouse -origY;
radians=Math.atan(newY/newX);
angle=(radians*180)/Math.PI;
aboveCamera._rotation = angle;
updateAfterEvent;
}
}

Thanks :)

Barnaby Kent
Re: Flash MX Event Model Rothrock
2/2/2004 6:08:04 PM
Where is this code? Is it in a setInterval() which is called from an on(press) handler attached to the movie clip?

If so you need to use a clearInterval() which is called from the on(release) handler.

Re: Flash MX Event Model BarneyK
2/3/2004 8:56:03 AM
Thanks for the reply,
I think I must have got the wrong idea with the MX Event Handler model. I thought you were not supposed to organise your code to be contained within on(press/release etc) handlers anymore, but rather add listeners to movie clips. At the moment the code is in a frame on the main timeline. Maybe I should go and buy a book on the topic. Thanks anyway

Barnaby Kent
Re: Flash MX Event Model Rothrock
2/3/2004 2:00:26 PM
My bad. I didn't completely read your code. You can do it the way you suggested as well. But the basic idea is still the same.

I don't have much experience with listeners, so I'm sure of the syntax, but if you have a listener for the click, do you have one listening for the release? I don't see an onMouseUp.

Re: Flash MX Event Model BarneyK
2/3/2004 3:39:08 PM
I have got it to work using flags, but I am not sure it is the best way to do it. Any suggestions welcome:


origX=aboveCamera._x;
origY=aboveCamera._y;
ROTATE=false;
_root.aboveCamera.onPress = function(){
ROTATE=true;
}
onMouseUp = function(){
ROTATE=false;
}
_root.aboveCamera.onRollOut = function(){
ROTATE=false;
}

onMouseMove = function(){
if(_root.ROTATE==true){
newX=this._xmouse -origX;//(Math.floor(aboveCamera._xmouse)) - origX;
newY=this._ymouse -origY;//(Math.floor(aboveCamera._ymouse)) - origY;
radians=Math.atan(newY/newX);
angle=(radians*180)/Math.PI;
aboveCamera._rotation = angle;
updateAfterEvent;
}
}

Barnaby Kent
Re: Flash MX Event Model BarneyK
2/11/2004 2:09:40 PM
The code I posted earlier does seem to work fine apart from one problem. As the
movie clip rotates instead of rotating from 0 angles to 360, it seems to rotate
fine from 1 to 180 but then instead of moving to a rotation value of 181 it
moves back to a value of 1. Any ideas
Cheer
AddThis Social Bookmark Button