package {
import flash.display.MovieClip
import flash.events.Event
public dynamic class dude extends MovieClip{
try
{
//public var _dude:dude;
public const TYNGDE:Number = 2;
private var _vx:Number = 0;
private var _vy:Number = 0;
public var _dude:dude;
public function Test():void {
try
{
_dude.x = 100;
_dude.y = 100;
}
catch ( e:Error )
{
trace("Feilen er: " + e);
}
addEventListener(Event.ENTER_FRAME, nyskjerm);
}
private function nyskjerm(e:Event):void{
_vy += TYNGDE;
try
{
_dude.x += _vx;
_dude.y += _vy;
}
catch ( e:Error )
{
trace("Feilen er: " + e);
}
SjekkBrett();
}
private function SjekkBrett():void{
if (_dude.x < 0 && _vx < 0){
_dude.x = 0;
_vx *= -1;
}
else if ((_dude.x+100) > stage.stageWidth && _vx > 0){
_dude.x = stage.stageWidth - 100;
_vx *= -1;
}
else if (_dude.y <0 && _vy <0){
_dude.y = 0;
_vy *= -1;
}
else if ((_dude.y+200) > stage.stageHeight && _vy > 0){
_dude.y = stage.stageHeight - 200;
_vy *= -0.8;
}
}
}
catch ( e:Error )
{
trace("Feilen er: " + e);
}
}}
I've tried giving the class the same name as the stage. I've tried not instanciating dude and just directly accessing it, also doesn't work. The error says the fault originates at line 1, but that doesn't make much sense to me. Help?
You are declaring a dude Object inside your dude class - i assume thats not what you want?
When you set "_dude.x = 100;", _dude has not been instantiated (ie: is null), so you cant set properties on it - resulting in error.
If im correct about your requirement, just replace "_dude" with "this" in your code and remove "public var _dude:dude;" completely.
And as user1875642 says; remove the try/catch declaration.