logotype/LeapMotionAS3

Undefined Property onInit using animate cc

Opened this issue · 2 comments

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