e:Frame is just plain wrong.
e:Event is absolutely correct. (check your code; the associated event listener is of type
Event.ENTER_FRAME)
You need to format this code and look at it again.
The enterframe handler "eFrame" is
outside of the package block.
Fix the structural issues and the 1046 error will probably go away.
ActionScript Code:
package
{
//imports
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class DirectBlock extends MovieClip
{//we'll call it a DirectBlock
private var _root:MovieClip;//again, defining a _root
private var directType:String;//what kind of special block is this
//this time, we have to accept some values to make it easier to place, like the type and coordinates
public function DirectBlock(type:String,xVal:int,yVal:int)
{
directType = type;//set the directType so that all other functions can use it
//add the required event listeners
this.addEventListener(Event.ADDED, beginClass);
this.addEventListener(Event.ENTER_FRAME, eFrame);
//setting the coordinates
this.x = xVal;
this.y = yVal;
}
private function beginClass(e:Event):void
{
_root = MovieClip(root);//setting the _root again
//making this into a 25x25 square
this.graphics.beginFill(0x111111);
this.graphics.drawRect(0,0,25,25);
this.graphics.endFill();
}
if (directType == 'START')
{
if (directType == 'START')
{//if this is a start block
//then define the startDir and StartCoord based on it's coordinates
if (x == 0)
{
_root.startDir = 'RIGHT';
_root.startCoord = y;
}
else if (y == 0)
{
_root.startDir = 'DOWN';
_root.startCoord = x;
}
else if (x == 525)
{
_root.startDir = 'LEFT';
_root.startCoord = y;
}
else if (y == 275)
{
_root.startDir = 'UP';
_root.startCoord = x;
}
else
{
}//this level won't work if not any of these values
}
}
else if (directType == 'FINISH')
{//if this is a finish block
//then define the finDir based on it's coordinates
if (x == 0)
{
_root.finDir = 'LEFT';
}
else if (y == 0)
{
_root.finDir = 'UP';
}
else if (x == 525)
{
_root.finDir = 'RIGHT';
}
else if (y == 275)
{
_root.finDir = 'DOWN';
}
else
{
}
}//this level won't work if not any of these values
}// <- end of class block
}// <- end of package block
/*-----------------------------------------------------------------------
Why is the following enter frame handler outside of the package block?
Should be inside of the Class block and set as private.
• corrected the event argument to e:Event
• the DirectBlock instance property _root is not accessible from here.
• class instances should not remove themselves from a parent.
the parent should handle this. Use Events to communicate with the parent.
-----------------------------------------------------------------------*/
function eFrame(e:Event):void
{
if (_root.gameOver == true)
{//destroy this if the game's over
this.removeEventListener(Event.ENTER_FRAME, eFrame);
MovieClip(this.parent).removeChild(this);
if (directType != 'START' && directType != 'FINISH')
{//if this isn't a start of finish block
//then it'll act as a directioning block
for (var i:int = 0; i<_root.enemyHolder.numChildren; i++)
{//create a loop
var enTarget = _root.enemyHolder.getChildAt(i);//this will hold a certain enemy
//if the enTarget's coordinates are too close to this block
if (this.x >= enTarget.x - enTarget.width*.5 && this.x <= enTarget.x + enTarget.width*.5
&& this.y >= enTarget.y - enTarget.height*.5 && this.y <= enTarget.y + enTarget.height*.5)
{
//then move the enemy's direction based on what direction this block points to
if (directType == 'UP')
{
enTarget.xSpeed = 0;
enTarget.ySpeed = - enTarget.maxSpeed;
}
else if (directType == 'RIGHT')
{
enTarget.xSpeed = enTarget.maxSpeed;
enTarget.ySpeed = 0;
}
else if (directType == 'DOWN')
{
enTarget.xSpeed = 0;
enTarget.ySpeed = enTarget.maxSpeed;
}
else if (directType == 'LEFT')
{
enTarget.xSpeed = enTarget.maxSpeed;
enTarget.ySpeed = 0;
}
}
}
}
}
}