SuperDwayne
05-18-2008, 04:07 PM
Ok hello everyone I am making a version of Grand Theft auto, its for my project at uni.
Anyway I want to do a basic when the car drives through the screen it goes on to the other screen (in coding terms it loads the other Swf), but when I do that and i want to go back not only is the car which i drove thought once is back in its original place also the new object I have dragged from the external Swf has followed it thought and now both are being controlled at the same :( Help
Code below this is the first part where the car drives through
var loader:Loader = new Loader();
addChild(loader);
function onCom(e:Event):void{
}
// Below are my two text fileds which display infomation/ instructions at diferent points in the game
var t_txt:TextField = new TextField();
t_txt.text = " Please click a different car for this mission";
t_txt.x = 150;
t_txt.y = 100;
t_txt.width =220;
t_txt.height = 20;
t_txt.border = true;
t_txt.textColor = 0x91A7FF;
t_txt.borderColor = 0xffffff;
t_txt.visible = false;
addChild(t_txt);
/*var p_txt:TextField = new TextField();
p_txt.text ="park here";
p_txt.x = 445;
p_txt.y = 75;
p_txt.height= 42;
p_txt.autoSize= "center"
p_txt.textColor = 0xffffff;
p_txt.visible = true;
addChild(p_txt);*/
var car:displayObject = car_mc;
var ambInfo1:Object = {xpos:472, ypos:156};
var ambInfo2:Object = {xpos:472, ypos:240};
var ambInfo3:Object = {xpos:472, ypos:320};
var ambInfo4:Object = {xpos:70, ypos:160};
var ambInfo5:Object = {xpos:70, ypos:240};
var ambInfo6:Object = {xpos:70, ypos:320};
var amb1:Ambulance = new Ambulance();
var amb2:Ambulance = new Ambulance();
var amb3:Ambulance = new Ambulance();
var amb4:Ambulance = new Ambulance();
var amb5:Ambulance = new Ambulance();
var amb6:Ambulance = new Ambulance();
addChild(amb6);
addChild(amb5);
addChild(amb4);
addChild(amb3);
addChild(amb2);
addChild(amb1);
amb1.x = ambInfo1.xpos;
amb1.y = ambInfo1.ypos;
amb2.x = ambInfo2.xpos;
amb2.y = ambInfo2.ypos;
amb3.x = ambInfo3.xpos;
amb3.y = ambInfo3.ypos;
amb4.x = ambInfo4.xpos;
amb4.y = ambInfo4.ypos;
amb5.x = ambInfo5.xpos;
amb5.y = ambInfo5.ypos;
amb6.x = ambInfo6.xpos;
amb6.y = ambInfo6.ypos;
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onCom);
stage.addEventListener(Event.ENTER_FRAME,park);
stage.addEventListener(Event.ENTER_FRAME, hitTest);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
stage.addEventListener(MouseEvent.CLICK, selectCar);
function selectCar(e:MouseEvent):void
{
//e.target
if(e.target == amb1){
trace ("you have slsected car 1")
}else{
if(e.target == amb2){
trace("you have selscted car 2")
}
}
car = e.target as MovieClip;
//when you click ambulance car the message please click a different car for this mission the message is removed
t_txt.visible = false;
}
function onDown (e:KeyboardEvent):void{
var dir:String
var speed:Number = 10;
switch (e.keyCode){
case Keyboard.LEFT:
car.rotation = 180
car.x -= speed;
break
case Keyboard.RIGHT:
car.rotation = 0
car.x += speed
break
case Keyboard.DOWN:
car.rotation = 90
car.y +=speed
break
case Keyboard.UP:
car.rotation = 270
car.y -=speed
break
case Keyboard.SPACE:
car.y /= speed
break
}
}
function hitTest (e:Event){
if (car.hitTestObject(top_mc))
t_txt.visible = true;
if (car.hitTestPoint(10,113)){
loader.load(new URLRequest('Ambstage1.swf'));
p_txt.visible =false;
amb1.visible = false;
amb2.visible = false;
amb3.visible = false;
amb4.visible = false;
amb5.visible = false;
amb6.visible = false;
car_mc.visible = false;
}
}
function park (e:Event){
if(car.hitTestObject(top_mc)){
p_txt.visible = false;
}
}
And this is the second part
var loader:Loader = new Loader();
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onCom);
function onCom(e:Event):void{
}
var car:displayObject = amb_mc;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
function onDown (e:KeyboardEvent):void{
var dir:String
var speed:Number = 10;
switch (e.keyCode){
case Keyboard.LEFT:
car.rotation = 180
car.x -= speed;
break
case Keyboard.RIGHT:
car.rotation = 0
car.x += speed
break
case Keyboard.DOWN:
car.rotation = 90
car.y +=speed
break
case Keyboard.UP:
car.rotation = 270
car.y -=speed
break
case Keyboard.SPACE:
car.y /= speed
break
}
if (car.hitTestPoint(490,81))
loader.load(new URLRequest('Ambulance_level.swf'));
}
p.s var car:displayObject = amb_mc; has a small d because it was making it into a smiley
Anyway I want to do a basic when the car drives through the screen it goes on to the other screen (in coding terms it loads the other Swf), but when I do that and i want to go back not only is the car which i drove thought once is back in its original place also the new object I have dragged from the external Swf has followed it thought and now both are being controlled at the same :( Help
Code below this is the first part where the car drives through
var loader:Loader = new Loader();
addChild(loader);
function onCom(e:Event):void{
}
// Below are my two text fileds which display infomation/ instructions at diferent points in the game
var t_txt:TextField = new TextField();
t_txt.text = " Please click a different car for this mission";
t_txt.x = 150;
t_txt.y = 100;
t_txt.width =220;
t_txt.height = 20;
t_txt.border = true;
t_txt.textColor = 0x91A7FF;
t_txt.borderColor = 0xffffff;
t_txt.visible = false;
addChild(t_txt);
/*var p_txt:TextField = new TextField();
p_txt.text ="park here";
p_txt.x = 445;
p_txt.y = 75;
p_txt.height= 42;
p_txt.autoSize= "center"
p_txt.textColor = 0xffffff;
p_txt.visible = true;
addChild(p_txt);*/
var car:displayObject = car_mc;
var ambInfo1:Object = {xpos:472, ypos:156};
var ambInfo2:Object = {xpos:472, ypos:240};
var ambInfo3:Object = {xpos:472, ypos:320};
var ambInfo4:Object = {xpos:70, ypos:160};
var ambInfo5:Object = {xpos:70, ypos:240};
var ambInfo6:Object = {xpos:70, ypos:320};
var amb1:Ambulance = new Ambulance();
var amb2:Ambulance = new Ambulance();
var amb3:Ambulance = new Ambulance();
var amb4:Ambulance = new Ambulance();
var amb5:Ambulance = new Ambulance();
var amb6:Ambulance = new Ambulance();
addChild(amb6);
addChild(amb5);
addChild(amb4);
addChild(amb3);
addChild(amb2);
addChild(amb1);
amb1.x = ambInfo1.xpos;
amb1.y = ambInfo1.ypos;
amb2.x = ambInfo2.xpos;
amb2.y = ambInfo2.ypos;
amb3.x = ambInfo3.xpos;
amb3.y = ambInfo3.ypos;
amb4.x = ambInfo4.xpos;
amb4.y = ambInfo4.ypos;
amb5.x = ambInfo5.xpos;
amb5.y = ambInfo5.ypos;
amb6.x = ambInfo6.xpos;
amb6.y = ambInfo6.ypos;
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onCom);
stage.addEventListener(Event.ENTER_FRAME,park);
stage.addEventListener(Event.ENTER_FRAME, hitTest);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
stage.addEventListener(MouseEvent.CLICK, selectCar);
function selectCar(e:MouseEvent):void
{
//e.target
if(e.target == amb1){
trace ("you have slsected car 1")
}else{
if(e.target == amb2){
trace("you have selscted car 2")
}
}
car = e.target as MovieClip;
//when you click ambulance car the message please click a different car for this mission the message is removed
t_txt.visible = false;
}
function onDown (e:KeyboardEvent):void{
var dir:String
var speed:Number = 10;
switch (e.keyCode){
case Keyboard.LEFT:
car.rotation = 180
car.x -= speed;
break
case Keyboard.RIGHT:
car.rotation = 0
car.x += speed
break
case Keyboard.DOWN:
car.rotation = 90
car.y +=speed
break
case Keyboard.UP:
car.rotation = 270
car.y -=speed
break
case Keyboard.SPACE:
car.y /= speed
break
}
}
function hitTest (e:Event){
if (car.hitTestObject(top_mc))
t_txt.visible = true;
if (car.hitTestPoint(10,113)){
loader.load(new URLRequest('Ambstage1.swf'));
p_txt.visible =false;
amb1.visible = false;
amb2.visible = false;
amb3.visible = false;
amb4.visible = false;
amb5.visible = false;
amb6.visible = false;
car_mc.visible = false;
}
}
function park (e:Event){
if(car.hitTestObject(top_mc)){
p_txt.visible = false;
}
}
And this is the second part
var loader:Loader = new Loader();
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onCom);
function onCom(e:Event):void{
}
var car:displayObject = amb_mc;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
function onDown (e:KeyboardEvent):void{
var dir:String
var speed:Number = 10;
switch (e.keyCode){
case Keyboard.LEFT:
car.rotation = 180
car.x -= speed;
break
case Keyboard.RIGHT:
car.rotation = 0
car.x += speed
break
case Keyboard.DOWN:
car.rotation = 90
car.y +=speed
break
case Keyboard.UP:
car.rotation = 270
car.y -=speed
break
case Keyboard.SPACE:
car.y /= speed
break
}
if (car.hitTestPoint(490,81))
loader.load(new URLRequest('Ambulance_level.swf'));
}
p.s var car:displayObject = amb_mc; has a small d because it was making it into a smiley