Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving object is not working but i have no errors
    text
    copied!<p>I wrote some actionscript 3 code for moving an object when another object gets close. I use flash cs5.5 The problem is that when i added some code for moving that object only once, the code stop working properly. Maybe the problem is not code itself but something in the objects or the instances of the objects but i didn't change anything. I am getting all the traces you can see in the code but when i close the "magnet" to the "pendulum" the pendulum is not moving-rotating as it did.</p> <pre><code>import flash.events.MouseEvent; import flash.events.Event; var angle:Number = 0; //angle for rotation of object "pendulum" var rotate:Number = 45; // value to multiple to calculate rotation //global variable var moved_once: int=0; //variable for checking the first move of the object function move_pendulum(e:Event):void{ trace("hit"); //to check if enters the function pendulum1.rotation = Math.sin(angle) * rotate; //execute rotation angle +=0.3; //increase angle for next rotation trace("hit2"); //to check if the function ends } magnet1.addEventListener(MouseEvent.MOUSE_DOWN, start_magnet); //for start dragging //object "magnet" magnet1.addEventListener(MouseEvent.MOUSE_UP, stop_magnet); //for stop dragging //object "magnet" function start_magnet(event:MouseEvent):void{ magnet1.startDrag(); //start dragging of object "magnet" //check if the two objects are close enough if(magnet1.x &gt;pendulum1.x &amp;&amp; (magnet1.x-pendulum1.x)&lt;100){ trace("range detect"); //check if it is the first time which the two objects are close enough if(moved_once==0){ trace("called move"); move_pendulum(event); //call function for rotating object "rotation" moved_once++; //increase counter for not rotating again } } }//end of function function stop_magnet(event:MouseEvent):void{ magnet1.stopDrag(); //stop dragging of object trace("stopped"); } </code></pre> <p>I got no error or anything else.What is going wrong? I can't see anything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload