PROBLEM SOLVED! THANK YOU: brart, TheCanadian, Krilnon
Intro.(Thank You)
Hello, thank you for taking the time to read this. I really appreciate you taking the time to try to assist me. I’m new to the forum and somewhat new to programming and have run into a mental wall.
Background.(Still Learning)
I have made a simple game for the purpose of furthering my knowledge on programming. It works as I expected but I would like to expand it further while using OOP which I still am having trouble grasping how to implement it. The concept I understand(I think). In the game I create an object and add it too the stage and would like to create more objects of a different type with similar function so converting the object into a super class and a sub class is the next logical step for me.
Problem.(Help)
I need to convert class Original into class Super and Class Sub.
Questions.(???)
[X] What does the Super class constructor need if I don’t call it? OR Do I need to call it?
[X] Do variables pass from Super to Sub?
[X] Do I need to import my Super Class in my Sub class?
[X] Does my pseudo code have any flaws in logic?
[X] 1203: No default constructor found in base class?
Pseudo Code.(//)
public class Original() extends MovieClip
{
private var a:Number;
public function Original()
{
One(a);
Two(a);
}
private function One(a:Number)
{
//Does Something with a
}
private function Two(a:Number)
{
//Does Something with a
}
}
…To be turned into…
public class Super() extends MovieClip
{
public var a:Number;
public function Super()
{
}
public function One(a:Number)
{
//Does Something with a
}
public function Two(a:Number)
{
//Does Something with a
}
}
public class Sub() extends Super
{
public function Sub()
{
One(a);
Two(a);
}
}
CODE.(#)
From Engine
...
unitThree = new SubCreature(stage);
...
From “Super”
package com.tisman.foodchain
{
import flash.display.MovieClip;
import flash.display.Stage
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Creature extends MovieClip
{
//MISC
public var stageRef:Stage;
//Variables For AI
public var up:Boolean = false;
public var left:Boolean = false;
public var right:Boolean = false;
public var turnTimer:Timer;
public var canTurn:Boolean = true;
// Variables for Movement.
public var speed:Number = 0.3;
public var rotateSpeed:Number = 2;
public var vx:Number = 0;
public var vy:Number = 0;
public var friction:Number = 0.95;
public var maxspeed:Number = 1;
//Variables For Collision
public var size:Number = 0;
public var growth:Number = 0;
public var growthRate:Number = 2;
public var kills:Number = 0;
public function Creature(stageRef:Stage) : void
{
this.stageRef = stageRef;
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
turnTimer = new Timer(700, 1);
turnTimer.addEventListener(TimerEvent.TIMER, turnTimerHandler, false, 0, true);
}
private function loop(e:Event) : void
{
if (canTurn == true)
{
aiDecision(this, Engine.unitList);
canTurn = false;
turnTimer.start();
}
movement();
collisions();
}
From Sub
package com.tisman.foodchain
{
import flash.display.Stage
public class SubCreature extends Creature
{
public function SubCreature(stageRef:Stage): void
{
super(stageRef);
}
}
}