Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-05-2012, 08:26 AM   #1
Rainbowjack
Registered User
 
Join Date: Mar 2012
Posts: 6
Default [AS3] error 1046 help

Hey guys,

I'm having trouble with this piece of code, it's for a tower defence game, the code is for a path on which enemies go from Point A to Point B. It says that the code is fine in the Actionscript file but when I publish the game it doesn't work. Here is the code, the error that comes up is Error 1046: Type was not found or was not a compile-time constant: Frame

The error is on Line 88.

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
};
};
function eFrame (e:Frame) :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;
}
}
}
}
}
}
Rainbowjack is offline   Reply With Quote
Old 03-05-2012, 08:42 AM   #2
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,427
Default

Frame is not a valid Event type; use Event instead, since that handler is for the enter frame Event.
ActionScript Code:
function eFrame(e:Event):void { }
[afz]snickelfitz is offline   Reply With Quote
Old 03-05-2012, 08:49 AM   #3
Rainbowjack
Registered User
 
Join Date: Mar 2012
Posts: 6
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
Frame is not a valid Event type; use Event instead, since that handler is for the enter frame Event.
ActionScript Code:
function eFrame(e:Event):void { }
I tried that, the same thing came up except with Event instead of Frame.
Rainbowjack is offline   Reply With Quote
Old 03-05-2012, 09:17 AM   #4
Syllogism
capt. Obvious
 
Syllogism's Avatar
 
Join Date: Aug 2006
Location: South Africa
Posts: 826
Default

you need to import the event class

put this at the top of your code after package {

import flash.events.Event;
__________________
S y l l o g i s m, Cptn Obvious

"I think you'll find my argument is flawless [Citation][Citation][Citation]"
Syllogism is offline   Reply With Quote
Old 03-05-2012, 09:22 AM   #5
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,427
Default

Quote:
Originally Posted by Syllogism View Post
you need to import the event class

put this at the top of your code after package {

import flash.events.Event;
He already has an events wildcard import.
[afz]snickelfitz is offline   Reply With Quote
Old 03-05-2012, 09:25 AM   #6
Syllogism
capt. Obvious
 
Syllogism's Avatar
 
Join Date: Aug 2006
Location: South Africa
Posts: 826
Default

whoops... my bad
__________________
S y l l o g i s m, Cptn Obvious

"I think you'll find my argument is flawless [Citation][Citation][Citation]"
Syllogism is offline   Reply With Quote
Old 03-05-2012, 09:21 AM   #7
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,427
Default

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;                     }                 }             }         }     } }
[afz]snickelfitz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:39 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.