Hi,
i have made a very simple application where i have created a ball which follows the mouse. However, seeing that i am new to this, what is the easiest/common way for me to be able to display the value of my “distance” variable without having to make my velFriction of type void? because if i make it void i can trace the distance value between the ball and the mouse but the ball moviclip stays still.
package
{
/**
* Zenos.as is meant to show how you can demonstrate friction using the Zenos Paradox theory
* @author Luong Vuong
* Date created: 21/12/2009
* Last modified: 21/12/2009
*/
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
public class Zenos extends Sprite
{
private var ball:MovieClip;
public function Zenos() :void
{
ball = new Ball();
ball.x = ball.y = 100;
construct();
}
// Add listeners and add UI to display list
public function construct() :void
{
addChild(ball);
addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
}
public function onLoop(evt:Event) :void
{
ball.x += velFriction(ball.x, mouseX, 5);
ball.y += velFriction(ball.y, mouseY, 5);
}
public function velFriction(orig:Number, dest:Number, coef:Number) :Number
{
var distance:Number = (dest - orig) / coef;
return distance ;
}
}
}
Thanks
This is taken from Learning Actionscript:A Beginners Guide pg. 128