Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined Property onInit using animate cc #59

Open
AnthonyLombard opened this issue Oct 19, 2017 · 2 comments
Open

Undefined Property onInit using animate cc #59

AnthonyLombard opened this issue Oct 19, 2017 · 2 comments

Comments

@AnthonyLombard
Copy link

As the title states Iam getting this error on this line

controller.addEventListener( LeapEvent.LEAPMOTION_INIT,onInit );

@AnthonyLombard
Copy link
Author

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" );
	}
}

@dkryder
Copy link

dkryder commented Oct 19, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants