Copy link to clipboard
Copied
Hi I'm a student doing an assignment where I need to animate an arrow flying to a falling target. As this is for a physics subject it needs to be in a lifelike environment hence using functions instead of motion tweening. I am new to AS3 and have some code that should use a parabola function to animate the flying arrow. I am getting three errors at the moment:
Here is the code:
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
{
public class Arrow extends MovieClip;
{
public static const g:Number = 10;
//our arrow
private var arrow:Shape;
//start velocities
private var ux:Number;
private var uy:Number;
public function Arrow()
{
arrow = new Shape();
arrow.graphics.lineStyle( 1, 0 );
arrow.graphics.lineTo( 30, 0 );
}
public function fire( vx:Number, vy:Number ):void
{
ux = vx;
uy = vy;
addChild( arrow );
addEventListener( Event.ENTER_FRAME, fly );
}
private function fly( e:Event ):void
{
//lets use our equations
var sx:Number = ux; //distance moved in x dir
var vy:Number = uy + g //new velocity in y dir
var sy:Number = uy + g/2 //distance moved in y dir
//apply to arrow
arrow.x += sx;
arrow.y += sy;
//save new y velocity
uy = vy;
//extra bonus rotation of arrow to point in the right direction
arrow.rotation = Math.atan2( uy, ux ) * 180 / Math.PI;
}
}
}
Any help to get this working would be greatly appreciated.
Note: This is in an external class file (.as) and is linked to the document class.
Get rid of the semicolon at the end of this line (5) and that might cure all of the errors...
public class Arrow extends MovieClip; <--- remove
Copy link to clipboard
Copied
Get rid of the semicolon at the end of this line (5) and that might cure all of the errors...
public class Arrow extends MovieClip; <--- remove
Find more inspiration, events, and resources on the new Adobe Community
Explore Now