LeapMotionAS3
LeapMotionAS3 copied to clipboard
Undefined Property onInit using animate cc
As the title states Iam getting this error on this line
controller.addEventListener( LeapEvent.LEAPMOTION_INIT,onInit );
Please mark this as a question, I cant seem to find where i am going wrong full code below
import com.leapmotion.leap.events.LeapEvent; import com.leapmotion.leap.Frame; import com.leapmotion.leap.Hand; import com.leapmotion.leap.Finger; import com.leapmotion.leap.Vector3; import com.leapmotion.leap.util.LeapUtil; import com.leapmotion.leap.Controller; import com.leapmotion.leap.Listener;
var controller = new Controller(); trace(controller);
controller.addEventListener( LeapEvent.LEAPMOTION_INIT,onInit ); controller.addEventListener( LeapEvent.LEAPMOTION_CONNECTED, onConnect ); controller.addEventListener( LeapEvent.LEAPMOTION_DISCONNECTED, onDisconnect ); controller.addEventListener( LeapEvent.LEAPMOTION_EXIT, onExit ); controller.addEventListener( LeapEvent.LEAPMOTION_FRAME, onFrame );
function onFrame( event:LeapEvent ):void { trace("On Frame"); // Get the most recent frame and report some basic information var frame:Frame = event.frame; trace( "Frame id: " + frame.id + ", timestamp: " + frame.timestamp + ", hands: " + frame.hands.length + ", fingers: " + frame.fingers.length + ", tools: " + frame.tools.length );
if ( frame.hands.length > 0 )
{
trace("hand if function");
var hand:Hand = frame.hands[ 0 ];
// Check if the hand has any fingers
var fingers:Vector.<Finger> = hand.fingers;
if ( fingers.length > 0 )
{
// Calculate the hand's average finger tip position
var avgPos:Vector3 = Vector3.zero();
for each ( var finger:Finger in fingers )
avgPos = avgPos.plus( finger.tipPosition );
avgPos = avgPos.divide( fingers.length );
trace( "Hand has " + fingers.length + " fingers, average finger tip position: " + avgPos );
}
// Get the hand's sphere radius and palm position
trace( "Hand sphere radius: " + hand.sphereRadius + " mm, palm position: " + hand.palmPosition );
// Get the hand's normal vector and direction
var normal:Vector3 = hand.palmNormal;
var direction:Vector3 = hand.direction;
// Calculate the hand's pitch, roll, and yaw angles
trace( "Hand pitch: " + LeapUtil.toDegrees( direction.pitch ) + " degrees, " + "roll: " + LeapUtil.toDegrees( normal.roll ) + " degrees, " + "yaw: " + LeapUtil.toDegrees( direction.yaw ) + " degrees\n" );
}
}
is there a space before oninit in the code?
On Thu, Oct 19, 2017 at 6:24 AM, Anthony Lombard [email protected] wrote:
Please mark this as a question, I cant seem to find where i am going wrong full code below
import com.leapmotion.leap.events.LeapEvent; import com.leapmotion.leap.Frame; import com.leapmotion.leap.Hand; import com.leapmotion.leap.Finger; import com.leapmotion.leap.Vector3; import com.leapmotion.leap.util.LeapUtil; import com.leapmotion.leap.Controller; import com.leapmotion.leap.Listener;
var controller = new Controller(); trace(controller);
controller.addEventListener( LeapEvent.LEAPMOTION_INIT,onInit ); controller.addEventListener( LeapEvent.LEAPMOTION_CONNECTED, onConnect ); controller.addEventListener( LeapEvent.LEAPMOTION_DISCONNECTED, onDisconnect ); controller.addEventListener( LeapEvent.LEAPMOTION_EXIT, onExit ); controller.addEventListener( LeapEvent.LEAPMOTION_FRAME, onFrame );
function onFrame( event:LeapEvent ):void { trace("On Frame"); // Get the most recent frame and report some basic information var frame:Frame = event.frame; trace( "Frame id: " + frame.id + ", timestamp: " + frame.timestamp + ", hands: " + frame.hands.length + ", fingers: " + frame.fingers.length + ", tools: " + frame.tools.length );
if ( frame.hands.length > 0 ) { trace("hand if function"); var hand:Hand = frame.hands[ 0 ];
// Check if the hand has any fingers var fingers:Vector.<Finger> = hand.fingers; if ( fingers.length > 0 ) { // Calculate the hand's average finger tip position var avgPos:Vector3 = Vector3.zero(); for each ( var finger:Finger in fingers ) avgPos = avgPos.plus( finger.tipPosition ); avgPos = avgPos.divide( fingers.length ); trace( "Hand has " + fingers.length + " fingers, average finger tip position: " + avgPos ); } // Get the hand's sphere radius and palm position trace( "Hand sphere radius: " + hand.sphereRadius + " mm, palm position: " + hand.palmPosition ); // Get the hand's normal vector and direction var normal:Vector3 = hand.palmNormal; var direction:Vector3 = hand.direction; // Calculate the hand's pitch, roll, and yaw angles trace( "Hand pitch: " + LeapUtil.toDegrees( direction.pitch ) + " degrees, " + "roll: " + LeapUtil.toDegrees( normal.roll ) + " degrees, " + "yaw: " + LeapUtil.toDegrees( direction.yaw ) + " degrees\n" );
} }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/logotype/LeapMotionAS3/issues/59#issuecomment-337906594, or mute the thread https://github.com/notifications/unsubscribe-auth/ADjNWrZJDVEQJ0iQDpNdcM0dQObZ8yuyks5st02SgaJpZM4P_OFC .