Hi,
I am new to this forum and I am currently trying build a Flash game based off of this tutorial. http://www.emanueleferonato.com/2009/09 ... prototype/
This ball does exactly what I want to do for my game but when I download the code and the source files that come with it. I open it up in my Adobe Flash CS5 try to run it and get this error.
Line 14 1046: Type was not found or was not a compile-time constant: arrow.
Here is all the code from the tutorial that I copied. I am fairly new to Box2d but I have a grasp on a lot of the aspects of it. My only guess is that this tutorial is a little old and the there is something in Adobe cs5 that I might now be seeing. Any help will be greatly appreciated. Thank you
I am new to this forum and I am currently trying build a Flash game based off of this tutorial. http://www.emanueleferonato.com/2009/09 ... prototype/
This ball does exactly what I want to do for my game but when I download the code and the source files that come with it. I open it up in my Adobe Flash CS5 try to run it and get this error.
Line 14 1046: Type was not found or was not a compile-time constant: arrow.
Here is all the code from the tutorial that I copied. I am fairly new to Box2d but I have a grasp on a lot of the aspects of it. My only guess is that this tutorial is a little old and the there is something in Adobe cs5 that I might now be seeing. Any help will be greatly appreciated. Thank you
Code:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.Math.*;
public class HelloWorld extends Sprite {
public var m_world:b2World;
public var m_iterations:int=10;
public var m_timeStep:Number=1.0/30.0;
public var the_arrow:arrow=new arrow(); <---This is where the error is pointing
public var the_arrow_angle:Number;
public var my_canvas:Sprite = new Sprite();
public var deg_to_rad:Number=0.0174532925;
public var rad_to_deg:Number=57.2957795;
public var charging:Boolean=false;
public var power:int=0;
public var impulse:Boolean=false;
public function HelloWorld() {
addChild(the_arrow);
addChild(my_canvas);
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-100.0, -100.0);
worldAABB.upperBound.Set(100.0, 100.0);
var gravity:b2Vec2=new b2Vec2(0.0,10.0);
var doSleep:Boolean=true;
m_world=new b2World(worldAABB,gravity,doSleep);
// debug draw
var m_sprite:Sprite;
m_sprite = new Sprite();
addChild(m_sprite);
var dbgDraw:b2DebugDraw = new b2DebugDraw();
var dbgSprite:Sprite = new Sprite();
m_sprite.addChild(dbgSprite);
dbgDraw.m_sprite=m_sprite;
dbgDraw.m_drawScale=30;
dbgDraw.m_alpha=1;
dbgDraw.m_fillAlpha=0.5;
dbgDraw.m_lineThickness=1;
dbgDraw.m_drawFlags=b2DebugDraw.e_shapeBit;
m_world.SetDebugDraw(dbgDraw);
// end debug draw
// Vars used to create bodies
var body:b2Body;
var bodyDef:b2BodyDef;
var boxDef:b2PolygonDef;
var circleDef:b2CircleDef;
// Add ground body
bodyDef = new b2BodyDef();
bodyDef.position.Set(10, 14);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(30, 1);
boxDef.friction=0.3;
boxDef.density=0;
body=m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
//
bodyDef = new b2BodyDef();
bodyDef.position.Set(5, 5);
circleDef = new b2CircleDef();
circleDef.radius=0.5;
circleDef.density=1.0;
circleDef.friction=0.5;
circleDef.restitution=0.2;
bodyDef.userData = new Sprite();
bodyDef.userData.name="Player";
body=m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
body.SetMassFromShapes();
//
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, shoot);
stage.addEventListener(MouseEvent.MOUSE_DOWN,charge);
}
public function Update(e:Event):void {
m_world.Step(m_timeStep, m_iterations);
for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next) {
if (bb.GetUserData()!=null) {
the_arrow.x=bb.m_userData.x=bb.GetPosition().x*30;
the_arrow.y=bb.m_userData.y=bb.GetPosition().y*30;
var dist_x=the_arrow.x-mouseX;
var dist_y=the_arrow.y-mouseY;
the_arrow_angle=Math.atan2(- dist_y,- dist_x);
the_arrow.rotation=the_arrow_angle*rad_to_deg;
if (charging) {
power++;
if (power>=120) {
power-=120;
}
my_canvas.graphics.clear();
my_canvas.graphics.lineStyle(3,0x000000,0.5);
draw_arc(my_canvas,the_arrow.x=bb.m_userData.x=bb.GetPosition().x*30,the_arrow.y=bb.m_userData.y=bb.GetPosition().y*30,20,270,270+power*3,1);
}
if (impulse) {
bb.ApplyImpulse(new b2Vec2(Math.cos(the_arrow_angle)*power/4, Math.sin(the_arrow_angle)*power/4),bb.GetWorldCenter());
impulse=false;
power=0;
}
}
}
}
public function charge(e:MouseEvent):void {
charging=true;
}
public function shoot(e:MouseEvent):void {
charging=false;
my_canvas.graphics.clear();
impulse=true;
}
public function draw_arc(movieclip,center_x,center_y,radius,angle_from,angle_to,precision):void {
var angle_diff=angle_to-angle_from;
var steps=Math.round(angle_diff*precision);
var angle=angle_from;
var px=center_x+radius*Math.cos(angle*deg_to_rad);
var py=center_y+radius*Math.sin(angle*deg_to_rad);
movieclip.graphics.moveTo(px,py);
for (var i:int=1; i<=steps; i++) {
angle=angle_from+angle_diff/steps*i;
movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
}
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.Math.*;
public class HelloWorld extends Sprite {
public var m_world:b2World;
public var m_iterations:int=10;
public var m_timeStep:Number=1.0/30.0;
public var the_arrow:arrow=new arrow(); <---This is where the error is pointing
public var the_arrow_angle:Number;
public var my_canvas:Sprite = new Sprite();
public var deg_to_rad:Number=0.0174532925;
public var rad_to_deg:Number=57.2957795;
public var charging:Boolean=false;
public var power:int=0;
public var impulse:Boolean=false;
public function HelloWorld() {
addChild(the_arrow);
addChild(my_canvas);
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-100.0, -100.0);
worldAABB.upperBound.Set(100.0, 100.0);
var gravity:b2Vec2=new b2Vec2(0.0,10.0);
var doSleep:Boolean=true;
m_world=new b2World(worldAABB,gravity,doSleep);
// debug draw
var m_sprite:Sprite;
m_sprite = new Sprite();
addChild(m_sprite);
var dbgDraw:b2DebugDraw = new b2DebugDraw();
var dbgSprite:Sprite = new Sprite();
m_sprite.addChild(dbgSprite);
dbgDraw.m_sprite=m_sprite;
dbgDraw.m_drawScale=30;
dbgDraw.m_alpha=1;
dbgDraw.m_fillAlpha=0.5;
dbgDraw.m_lineThickness=1;
dbgDraw.m_drawFlags=b2DebugDraw.e_shapeBit;
m_world.SetDebugDraw(dbgDraw);
// end debug draw
// Vars used to create bodies
var body:b2Body;
var bodyDef:b2BodyDef;
var boxDef:b2PolygonDef;
var circleDef:b2CircleDef;
// Add ground body
bodyDef = new b2BodyDef();
bodyDef.position.Set(10, 14);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(30, 1);
boxDef.friction=0.3;
boxDef.density=0;
body=m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
//
bodyDef = new b2BodyDef();
bodyDef.position.Set(5, 5);
circleDef = new b2CircleDef();
circleDef.radius=0.5;
circleDef.density=1.0;
circleDef.friction=0.5;
circleDef.restitution=0.2;
bodyDef.userData = new Sprite();
bodyDef.userData.name="Player";
body=m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
body.SetMassFromShapes();
//
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, shoot);
stage.addEventListener(MouseEvent.MOUSE_DOWN,charge);
}
public function Update(e:Event):void {
m_world.Step(m_timeStep, m_iterations);
for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next) {
if (bb.GetUserData()!=null) {
the_arrow.x=bb.m_userData.x=bb.GetPosition().x*30;
the_arrow.y=bb.m_userData.y=bb.GetPosition().y*30;
var dist_x=the_arrow.x-mouseX;
var dist_y=the_arrow.y-mouseY;
the_arrow_angle=Math.atan2(- dist_y,- dist_x);
the_arrow.rotation=the_arrow_angle*rad_to_deg;
if (charging) {
power++;
if (power>=120) {
power-=120;
}
my_canvas.graphics.clear();
my_canvas.graphics.lineStyle(3,0x000000,0.5);
draw_arc(my_canvas,the_arrow.x=bb.m_userData.x=bb.GetPosition().x*30,the_arrow.y=bb.m_userData.y=bb.GetPosition().y*30,20,270,270+power*3,1);
}
if (impulse) {
bb.ApplyImpulse(new b2Vec2(Math.cos(the_arrow_angle)*power/4, Math.sin(the_arrow_angle)*power/4),bb.GetWorldCenter());
impulse=false;
power=0;
}
}
}
}
public function charge(e:MouseEvent):void {
charging=true;
}
public function shoot(e:MouseEvent):void {
charging=false;
my_canvas.graphics.clear();
impulse=true;
}
public function draw_arc(movieclip,center_x,center_y,radius,angle_from,angle_to,precision):void {
var angle_diff=angle_to-angle_from;
var steps=Math.round(angle_diff*precision);
var angle=angle_from;
var px=center_x+radius*Math.cos(angle*deg_to_rad);
var py=center_y+radius*Math.sin(angle*deg_to_rad);
movieclip.graphics.moveTo(px,py);
for (var i:int=1; i<=steps; i++) {
angle=angle_from+angle_diff/steps*i;
movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
}
}
}
}