PDA

View Full Version : Reconsize if a movie clip has been shaken??


chris_angell
07-11-2008, 03:47 PM
i am trying to write some code to detect if a movie clip has been shaken.. ie

if (movieClip._x = -5 && movieClip._x = +5 ){
??????????????
}

any help would be good...

gnomeontherun
07-11-2008, 05:51 PM
Ok that conditional will never be reached. Never at any point can the clip have moved both left and right at the same exact instance.

I would think the best method would be a bit complicated, but I'll try to explain my idea. You could have the script make a time function which will run for a second, and then you can have two conditional statements which will check if the movieClip has been moved far enough left or right. If the condition is met, set a variable to true. Then have one last conditional that checks if both left and right conditions were met by testing if the two variables are true. If so, then you'll know.

This code is just a representation of my thoughts, not actual code.

movieClip.onPress = timerfunction....{
if (check if left) {
leftShake = true;
}
if (check if right) {
rightShake = true;
}
if (leftShake == true && rightShake == true) {
shaken = true;
}
}

chris_angell
07-14-2008, 11:11 AM
Hi i have put together some code.. but its not working that well... if any body could put a suggestion how to do it any better that would be great..

what i am trying to do ,, is detect is a movie clip has been shaken onStartDrag ???? ie, left and right or up and down pretty fast #?? this is my attempt...


this.lastX = 0
dir = 'none';

if (this._xmouse > this.lastX) {
if (dir == 'left' && ( Math.abs( this.lastX - this._xmouse) > 5) {
trace('shakin stevens');
}
dir = 'right';
this.lastX = this._xmouse;
} else if (this._xmouse < this.lastX) {
// Flip Above Code here
dir = 'left'
} else {
dir = 'none'
}

gnomeontherun
07-14-2008, 03:38 PM
Can you post the whole function with onStartDrag? I think you have to realize that that will fire once on the Start of Dragging. You should look at how the functions are called by Flash to figure out if you are calling your functions everytime the mouse is moved or everytime the mouse Starts to drag without letting up on the mouse.