i have made a class file player and another class file landscape. the player class file has meathods that allow the player to move. where would i put code to make the landscape move with the player? would the code go into the player class file or the document class file? i dont know how i could link the landscape movement with hte player movement
player.as class file
//the package
package actionscript{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import actionscript.utils.KeyObject;
import flash.ui.*;
public class player extends MovieClip {
private var pspeed:Number = 5;
private var key:KeyObject;
private var stageRef:Stage;
public function player(stageRef:Stage) {
trace("Player is on");
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);// add a loop
this.stageRef = stageRef;
key = new KeyObject(stageRef);
}
public function loop(e:Event):void {
var playerHalfWidth:uint = this.width /2;
var playerHalfHeight:uint = this.height /2;
if (key.isDown(Keyboard.LEFT)) {
x -= pspeed;
} else if (key.isDown(Keyboard.RIGHT)) {
x += pspeed;
}
if (key.isDown(Keyboard.UP)) {
y -= pspeed;
} else if (key.isDown(Keyboard.DOWN)) {
y += pspeed;
}
if (x > stageRef.stageWidth) {
x = stageRef.stageWidth;
} else if (x < 0) {
x = 0;
}
if (y > stageRef.stageHeight) {
y = stageRef.stageHeight;
} else if (y < 0) {
y = 0;
}
if (this.x +playerHalfWidth > stageRef.stageWidth) {
this.x = stageRef.stageWidth - playerHalfWidth;
} else if (this.x - playerHalfWidth < 0) {
this.x = 0 + playerHalfWidth;
}
if (this.y +playerHalfHeight > stageRef.stageHeight) {
this.y = stageRef.stageHeight - playerHalfHeight;
} else if (this.y - playerHalfHeight < 0) {
this.y = 0 + playerHalfHeight;
}
}
}
}
engine.as document class file
//the package
package actionscript
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
public class engine extends MovieClip
{
private var theplayer:player;
private var thelandscape:land;
public function engine()
{
trace ("Engine is on");
theplayer = new player(stage); //human player
thelandscape = new land(); //flashlight
stage.addChild(thelandscape); // adding the flashlight
stage.addChild(theplayer); // adding the room
theplayer.x = stage.stageWidth / 2; //positioning the player in x
theplayer.y = stage.stageHeight / 2;
thelandscape.x = stage.stageWidth / 2; //positioning the player in x
thelandscape.y = stage.stageHeight / 2;
}
}
}
landscape class file
package actionscript
{
import flash.display.MovieClip;
public class land extends MovieClip
{
public function land()
{
trace ("landscape is on");
}
}
}