|
From: <acl...@us...> - 2006-10-12 20:17:31
|
Revision: 587
http://svn.sourceforge.net/asapframework/?rev=587&view=rev
Author: aclemens
Date: 2006-10-12 13:17:25 -0700 (Thu, 12 Oct 2006)
Log Message:
-----------
overload callback function to accept method name and function reference;
doc update
Modified Paths:
--------------
trunk/asapframework/org/asapframework/util/actionqueue/AQFollowMouse.as
Modified: trunk/asapframework/org/asapframework/util/actionqueue/AQFollowMouse.as
===================================================================
--- trunk/asapframework/org/asapframework/util/actionqueue/AQFollowMouse.as 2006-10-12 09:19:40 UTC (rev 586)
+++ trunk/asapframework/org/asapframework/util/actionqueue/AQFollowMouse.as 2006-10-12 20:17:25 UTC (rev 587)
@@ -44,7 +44,7 @@
@param inLocDiv : (optional) the translation factor of the mouse movements, relative to its parent's center point; an inLocDiv of 2 multiplies all x and y (difference) locations by 2. The visual effect works best if the parent has its (0,0) location at its center. The value should not be smaller than inTimeDiv (and is set automatically to the value of inTimeDiv if it is smaller); default (when nothing is set) is 1.0.
@param inOffset : (optional) the number of pixels to offset the clip from the mouse, defined as a Point object
@param inCallbackObject : (optional) object to return the calculated value to; if defined, the drawing is not performed by <code>followMouse</code> and should be done in the object's callback method inCallBackMethod
- @param inCallBackMethod : (optional) the object's method to which the calculated value should be returned; the variable that is passed to this object is a {@link Point}
+ @param inCallBackMethod : (optional) method name or function reference of function to which the calculated value should be returned; the variable that is passed to this object is a {@link Point}
@return A new ActionQueuePerformData object.
@example
The most simple way to let a movieclip move infinitely to the mouse is:
@@ -69,6 +69,35 @@
my_mc._y = (STAGE_CENTER.y - inPos.y) * 0.25;
}
</code>
+ To keep the MovieClip oriented to the mouse position, you can use this function:
+ <code>
+ private function followMouseLoc (inPos:Point) : Void {
+
+ var dx:Number = inPos.x - graphic_mc._x;
+ var dy:Number = inPos.y - graphic_mc._y;
+ var d:Point = new Point(dx, dy);
+
+ var startRotation:Number = graphic_mc._rotation;
+ var endRotation:Number = NumberUtils.angle(d.x, d.y);
+ var changeRotation:Number = endRotation - startRotation;
+
+ if ((360 - changeRotation) < changeRotation) {
+ changeRotation = changeRotation - 360;
+ }
+ if (360 - Math.abs(changeRotation) < Math.abs(changeRotation)) {
+ changeRotation = 360 - Math.abs(changeRotation);
+ }
+ // do not rotate if the rotation will not be visible:
+ if (Math.abs(changeRotation) > .5 ) {
+ graphic_mc._rotation = endRotation - ((1 - ROTATION_EASE_FACTOR) * changeRotation);
+ }
+
+ // position clip
+ graphic_mc._x = inPos.x;
+ graphic_mc._y = inPos.y;
+ }
+ </code>
+ Where <code>ROTATION_EASE_FACTOR</code> is 0 < n <= 1.
*/
public static function followMouse (inMC:MovieClip,
@@ -77,7 +106,7 @@
inLocDiv:Number,
inOffset:Point,
inCallbackObject:Object,
- inCallBackMethod:String) : ActionQueuePerformData {
+ inCallBackMethod:Object) : ActionQueuePerformData {
var duration:Number = (inDuration != undefined) ? inDuration * 1000 : 0;
var endTime:Number = getTimer() + duration;
@@ -90,7 +119,13 @@
var offsetX:Number = (inOffset != undefined) ? inOffset.x : 0;
var offsetY:Number = (inOffset != undefined) ? inOffset.y : 0;
- var callbackMethod:Function = (inCallbackObject != undefined) ? inCallbackObject[inCallBackMethod] : null;
+ var callbackMethod:Function = null;
+ if (typeof inCallBackMethod == "string") {
+ callbackMethod = inCallbackObject[inCallBackMethod];
+ }
+ if (typeof inCallBackMethod == "function") {
+ callbackMethod = Function(inCallBackMethod);
+ }
var draw:Function;
var parent:MovieClip = inMC._parent;
var point:Point = new Point(inMC._x, inMC._y);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|