This is what i did:
1. I made a square, about 30 Pixels width and height, and made it a movie clip (centre point registered as centre, named it "Object"). In the properties panel, i called it "object1" as an instance name.
2. i clicked on the main stage in scene 1/layer 1/frame 1, and pressed F9. I wanted my "square" to go the opposite direction as my mouse, getting slower/faster due to the position of my mouse. I did it in the X co-ordinates of the mouse. I didn't want the "square" to zoom in/out, get fainter/thicker like on that site.
3. Here's my code i used. I made it up, no help from tutorials or other sites... just used my logic of math and such
CODE
onEnterFrame = function () {
xM = _xmouse-object1._x;
object1.onEnterFrame = function() {
oM = this._x-(xM*Math.PI/180);
this._x = oM;
if (xM < this._x){
xM = -_xmouse-object1._x;
}
if (xM > this._x){
xM = _xmouse-object1._x;
}
};
};
xM = _xmouse-object1._x;
object1.onEnterFrame = function() {
oM = this._x-(xM*Math.PI/180);
this._x = oM;
if (xM < this._x){
xM = -_xmouse-object1._x;
}
if (xM > this._x){
xM = _xmouse-object1._x;
}
};
};
4. I understand partially the meaning... of my own code; i have used every one of these variables/code in other things, but never understood fully their meaning.
Lets see... Look at variable xM in the code above. it says in english "xM is the position of the x of the mouse, minus object1's x position"
For example it could be... _xmouse could be 20, object1._x could be 225, so 20 - 225 is -205.
next is variable oM... for example, "oM = 225-(-205*3.142/180)" in short, "oM = 225--3.57" or "oM = 225+3.57". Still isn't making much sense to me either, so don't worry
Ok, if we didn't add the remainder of the code "...if (xM < this._x...", then the object would only go one way, even if your mouse was on the opposite side of the object! so this code comes in handy, saying "If the mouse is greater than object, xM = -xM" and so on so forth.
I tested the movie, and the object moved according to the mouse position... In more advanced situations there could be a point when i actually make the object circle an orb!

Sign In
Register
Help



MultiQuote