# \[FLASH 8 actionscript\] Desperately need help with compass

**URL:** <https://forum.kirupa.com/t/flash-8-actionscript-desperately-need-help-with-compass/178049>\
**Category:** flash\
**Created:** [February 7, 2006, 12:34pm UTC](https://forum.kirupa.com/t/flash-8-actionscript-desperately-need-help-with-compass/178049 "2006-02-07T12:34:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phatsjunx](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@phatsjunx](https://forum.kirupa.com/u/phatsjunx)\
**Post date:** [February 7, 2006, 12:34pm UTC](https://forum.kirupa.com/t/flash-8-actionscript-desperately-need-help-with-compass/178049/1 "2006-02-07T12:34:26Z")

</div>

[FONT=Arial][SIZE=2]i’ve gone through several forums and tutorials to figure out how to make a compass react to a magnet. i’m quite new to flash and i’m an entry level in my company and they want me to create this simple animation and i’m already having problems with it :\*(  
i’ve specifically told them that my experience with flash is limited but now they want me to become an instant expert at it!

i know how to use flash but my actionscripting skills are terrible, especially with the math stuff. i’ve seen several tutorials of an arrow attracted to the mouse cursor point but i haven’t seen any that shows an arrow repelling away from a cursor. i’ve used this [COLOR=Black]example:

[/COLOR][COLOR=Black][FONT=Tahoma][http://www.flashkit.com/movies/Scripting/Maths/Detect\_a-Mark\_Otw-4100/index.php[/FONT][/COLOR]](http://www.flashkit.com/movies/Scripting/Maths/Detect_a-Mark_Otw-4100/index.php%5B/FONT%5D%5B/COLOR%5D)**[COLOR=Black][FONT=Tahoma]  
[/FONT][/COLOR][COLOR=navy][COLOR=navy][FONT=Tahoma]**[COLOR=Black]  
[/COLOR]**[/FONT][/COLOR][/COLOR]**[COLOR=navy][COLOR=navy][FONT=Tahoma][COLOR=Black] but the coding was a bit too complex so i ended up using the coding (sorry don’t mean to steal…using for practice purpose!) from some other tutorial which i can’t seem to find right now.

**[FONT=Arial]I AM TRYING TO ACHIEVE:[/FONT]**[/COLOR][/FONT][/COLOR][/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2]

1. [http://webphysics.davidson.edu/mjb/SESAPS2000/magnets.html](http://webphysics.davidson.edu/mjb/SESAPS2000/magnets.html)  
(this is the javascript version…you have to click on “Animation 2” and “Add compass”)

[/SIZE][/FONT] [FONT=Arial][SIZE=2]OR

[/SIZE][/FONT] [FONT=Arial][SIZE=2]2. [http://www.edumedia.fr/a179\_l2-bar-magnet-2.html](http://www.edumedia.fr/a179_l2-bar-magnet-2.html)  
(i need the opposite of this where I can move the compass instead of the magnet)

[/SIZE][/FONT] [FONT=Arial][SIZE=2]can someone please please help? i need to present this to my bosses by the end of the week! can anyone recommend a good actionscript book that will help shed some light for me? :cantlook:

**SO FAR:**  
i am able to drag my compass around the magnet which is centered on the stage. i have two movie clips called point\_N and point\_S and i’m trying to get the compass to either attract or repel when put near the ends of the magnet. this is the code i have so far on the compass movie clip:

[/SIZE][/FONT] [FONT=Arial][SIZE=2][COLOR=Gray] //trying to get the compass to react to point\_N of the magnet!  
//not working correctly…  
//movieclips point\_S and point\_N are currently visible for aid purposes…  
//i intend to put them underneath the magnet in the end…if i ever get this figured out![/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2]  
[COLOR=Gray]//overall, reacts funny[/COLOR]

[/SIZE][/FONT] [FONT=Arial][SIZE=2][COLOR=Navy] onClipEvent (enterFrame) {  
mouse\_x = int(\_root.point\_N.\_x-this.\_x);  
mouse\_y = int(\_root.point\_N.\_y-this.\_y);  
if (mouse\_x\>0 && mouse\_y\>0) {  
quad = Number(4);  
}  
if (mouse\_x\<0 && mouse\_y\>0) {  
quad = Number(1);  
}  
if (mouse\_x\<0 && mouse\_y\<0) {  
quad = Number(2);  
}  
if (mouse\_x\>0 && mouse\_y\<0) {  
quad = Number(3);  
}

```
abs_x = Math.abs(mouse_x);
abs_y = Math.abs(mouse_y);
tg = abs_y/abs_x;
_root.maths = Math.atan(tg)*Number(180)/Math.PI;
 if (quad == 1) { angle = number(90) + number(_root.maths) }
if (quad == 2) { angle = number(90) - number(_root.maths) }
 if (quad == 3) { angle = number(270) - number(_root.maths) }
 if (quad == 4) { angle = number(270) + number(_root.maths) }
setProperty (_this, _rotation, angle);

```

}

[/COLOR][/SIZE][/FONT] [FONT=Arial][SIZE=2]

this is the code i have on the compass’s hit area (which allows me to drag and move it)

[/SIZE][/FONT] [FONT=Arial][SIZE=2][COLOR=Navy] on (press) {  
startDrag(this, true, 15, 15, 535, 435);  
this.swapDepths(\_root.x );  
}  
on (release) {  
stopDrag();  
}[/COLOR][/SIZE][/FONT][FONT=Arial][SIZE=2]

I hope someone can help me! i know this is very simple but stupid me can’t figure this thing out! i’d really appreciate your help.[/SIZE][/FONT]
