PDA

View Full Version : Problems setting variables in extended class


pixelrevision
12-07-2007, 05:59 PM
I'm having problems with setting a variable in an extended class file. For whatever reason the variable walkable is coming up as undefined. Can anyone help me with this?

The super class is:

package com.pixelrevision.tilez.tiles{
public class Tile{
public var walkable:Boolean;
public function Tile(){
walkable = true;
}
}

}

And extending it is:

package com.pixelrevision.tilez.tiles{
import com.pixelrevision.tilez.tiles.Tile;
public class WallTile extends Tile{
public function WallTile(){
super();
walkable = false;
}
}
}

Slowburn
12-07-2007, 08:35 PM
try putting 'this' in front of the variable when setting it

pixelrevision
12-07-2007, 08:45 PM
It still seems to come back as undefined.

Nomad2000
12-07-2007, 10:00 PM
Just tried it and it works fine for me (as I expected after looking at the code).

Have you added the path to your custom files to your AS 3.0 classpath? Preferences->ActionScript->ActionScript 3.0 Settings.

By the way, you don't need to import classes that are in the same package, so the import statemnt in your WallTile class is not required.

pixelrevision
12-07-2007, 10:21 PM
double checked the class path. It works and is loading other stuff from the same folders.

Does it live in a different space? When I use:

var myTile = new WalkTile();
trace(myTile.walkable);

it returns undefined.

if I set it to:
var myTile = new WalkTile();
myTile.walkable = true;
trace(myTile.walkable);

I get the true value returned.

pixelrevision
12-07-2007, 10:55 PM
Thanks for all the attempted help. Reinstalling CS3 seemed to solve the problem.