# Actionscript 3.0 custom classes

**URL:** <https://forum.kirupa.com/t/actionscript-3-0-custom-classes/328700>\
**Category:** flash\
**Created:** [June 7, 2012, 10:13pm UTC](https://forum.kirupa.com/t/actionscript-3-0-custom-classes/328700 "2012-06-07T22:13:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ragnoroct](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@Ragnoroct](https://forum.kirupa.com/u/Ragnoroct)\
**Post date:** [June 7, 2012, 10:13pm UTC](https://forum.kirupa.com/t/actionscript-3-0-custom-classes/328700/1 "2012-06-07T22:13:29Z")

</div>

Dear Kirupa members,

I am trying to construct a small flash game using two classes for learning purposes. I have a small understanding of super-classes and sub-classes. The game partially works with one class doing stuff but when I try to incorporate the second class(things like creating a variable in one and then trying to trace it from the other class) I get errors. I’ve searched all over the internet but I haven’t really come across anything that explained how to make programs with multiple class communicating with each other where I was able to understand the tutorial 😛

I have a fla file with 3 movie clips with the linkage of  
_Bob  
Projectile  
StartButton_

and then I have these two classes

package  
{  
import flash.display.Sprite;  
import flash.events.MouseEvent;  
import flash.utils.Timer;  
import flash.events._;  
import flash.utils.getTimer;  
//import DodgeSubClass._;

public class Dodge extends Sprite  
{  
private var mcBob:Bob;  
static const mcBobDX = 200;  
//how fast he strides  
static const mcBobSS = 1;  
private var leftArrow:Boolean = false;  
private var rightArrow:Boolean = false;  
private var upArrow:Boolean = false;  
private var bottomArrow:Boolean = false;  
private var mcStartButton:StartButton;  
public var lastTime:int;  
private var mcBobX:Number = 263;  
private var mcBobY:Number = 199;  
public var totalObjects:Array;  
public var ballNumber:uint;  
public var id = 22;

public function Dodge()  
{  
mcStartButton = new StartButton;  
mcStartButton.x = 254;  
mcStartButton.y = 231;  
mcStartButton.gotoAndStop(1);  
addChild(mcStartButton);  
mcStartButton.addEventListener(MouseEvent.CLICK, startGame);

}  
//start game  
public function startGame (event:MouseEvent):void  
{  
//deleting and switching  
removeChild(mcStartButton);  
mcStartButton.removeEventListener(MouseEvent.CLICK, startGame);  
mcBob = new Bob();  
mcBob.gotoAndStop(1);  
mcBob.x = mcBobX;  
mcBob.y = mcBobY;  
addChild(mcBob);  
stage.addEventListener(KeyboardEvent.KEY\_DOWN, keyDown);  
stage.addEventListener(KeyboardEvent.KEY\_UP, keyUp);  
addEventListener(Event.ENTER\_FRAME, bobAnimation);  
lastTime = getTimer();  
}  
//Animation  
private function bobAnimation(event:Event):void  
{

var timePassed:int = getTimer() - lastTime;  
lastTime += timePassed;  
//check boundries////////////////////////////////////////////////  
if (leftArrow == true)  
{

if (mcBob.x\<18)  
{  
leftArrow = false;  
mcBob.x= 23;  
}  
}  
if (rightArrow == true)  
{  
if (mcBob.x\>530)  
{  
rightArrow = false;  
mcBob.x = 530;

}  
}  
if (upArrow == true)  
{  
if (mcBob.y\<15)  
{  
upArrow = false;  
mcBob.y = 13;  
}  
}  
if (bottomArrow == true)  
{  
if (mcBob.y\>381)  
{  
bottomArrow = false;  
mcBob.y = 381;  
}  
}  
///move object  
if (leftArrow == true)  
{  
mcBobX += (mcBobDX_timePassed/1000)_-1;  
mcBob.rotation = 270;

}  
if (rightArrow == true)  
{  
mcBobX += (mcBobDX\*timePassed/1000);  
mcBob.rotation = 90;

}

if (upArrow == true)  
{  
mcBobY += (mcBobDX_timePassed/1000)_-1;  
mcBob.rotation = 0;

}  
if (bottomArrow == true)  
{  
mcBobY += (mcBobDX\*timePassed/1000);  
mcBob.rotation = 180;

}

mcBob.x = mcBobX;  
mcBob.y = mcBobY;

}

//character facing different directions and strides

public function keyDown(event:KeyboardEvent):void  
{  
if (event.keyCode == 37)  
{  
leftArrow = true;  
if (mcBob.x\<23)  
{  
leftArrow = false;  
mcBob.x = 23;  
}  
}  
else if (event.keyCode == 39)  
{  
rightArrow = true;  
}  
else if (event.keyCode == 38)  
{  
upArrow = true;  
}  
else if (event.keyCode == 40)  
{  
bottomArrow = true;  
}  
}

public function keyUp(event:KeyboardEvent):void  
{  
if (event.keyCode == 37)  
{  
leftArrow = false;

}  
else if (event.keyCode == 39)  
{  
rightArrow = false;  
}  
else if (event.keyCode == 38)  
{  
upArrow = false;  
}  
else if (event.keyCode == 40)  
{  
bottomArrow = false;  
}  
}

}

}

the second class I’m trying to use is

package {

public class DodgeSubclass extends Dodge {

public function DodgeSubclass() {  
trace(“works”);  
}

}

}

The program works but “works” does not trace in the output panel.

Thanks!
