So I created something that’ll allow me to have a character and walk with it, but I did this all in the document class. And because this is going to be more complicated I wanted to move that to a Character class. So I did this:
Document Class:
package
{
import Character;
import flash.display.*;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class VelunaStory extends MovieClip
{
private var myParent:Sprite;
public static var STAGE:Stage;
private var player:Character;
public function VelunaStory()
{
STAGE = this.stage;
player = new Character();
}
}
}
Then I have my Character class:
package
{
import KeyObject;
import flash.display.*;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class Character extends VelunaStory
{
private var dir:int;
private var speed:Number = 5;
private var moveX:int;
private var moveY:int;
private var walking:Boolean;
private var character:hero;
private var Key:KeyObject;
public function Character()
{
character = new hero;
character.x = character.y = 200;
STAGE.addChild(character);
dir = 0;
walking = false;
character.gotoAndStop('front_stand');
Key = new KeyObject(STAGE);
STAGE.addEventListener(Event.ENTER_FRAME, onenter);
}
private function walkAnimation(event:Event):void
{
if((character.x - moveX) * (character.x - moveX) + (character.y - moveY) * (character.y - moveY) <= speed * speed)
{
character.x = moveX;
character.y = moveY;
walking = false;
return;
}
var angle:Number = Math.atan2(moveY - character.y, moveX - character.x);
character.x = character.x + Math.cos(angle) * speed;
character.y = character.y + Math.sin(angle) * speed;
}
function onenter(e:Event):void
{
if(walking) return;
if(Key.isDown(Key.RIGHT))
{
dir = 1;
walking = true;
character.gotoAndStop('front_walking');
moveX = character.x + 20;
moveY = character.y + 20;
character.addEventListener(Event.ENTER_FRAME, walkAnimation);
character.scaleX = -1;
}
else if(Key.isDown(Key.LEFT))
{
dir = 3;
walking = true;
character.gotoAndStop('back_walking');
moveX = character.x - 20;
moveY = character.y - 20;
character.addEventListener(Event.ENTER_FRAME, walkAnimation);
character.scaleX = -1;
}
else if(Key.isDown(Key.UP))
{
dir = 2;
walking = true;
character.gotoAndStop('back_walking');
moveX = character.x + 20;
moveY = character.y - 20;
character.addEventListener(Event.ENTER_FRAME, walkAnimation);
character.scaleX = 1;
}
else if(Key.isDown(Key.DOWN))
{
dir = 0;
walking = true;
character.gotoAndStop('front_walking');
moveX = character.x - 20;
moveY = character.y + 20;
character.addEventListener(Event.ENTER_FRAME, walkAnimation);
character.scaleX = 1;
}
else
{
switch(dir)
{
case 0:
character.scaleX = 1;
character.gotoAndStop('front_stand');
break;
case 1:
character.scaleX = -1;
character.gotoAndStop('front_stand');
break;
case 2:
character.scaleX = 1;
character.gotoAndStop('back_stand');
break;
case 3:
character.scaleX = -1;
character.gotoAndStop('back_stand');
break;
}
}
}
}
}
Now the issue is when is on the line in my character class that calls the new Character(); Because when I comment it out, I don’t get it anymore.
I get this error: Error: Error #2136: The SWF file …/vs.swf contains invalid data.
at VelunaStory()
I don’t think it’s anything inside the Character class because I tried commenting out all the functionality so it’s just a shell of a class and I still get this error.
Anyone know what’s going on?