Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Thread Tools Rate Thread Display Modes
Old 11-03-2010, 10:32 PM   #1
Registered User
Join Date: Oct 2010
Posts: 5
Default [AS3] Help destroying everything at end of level?

So... I'm working on a game, where the essential gameplay element is that you walk through a maze with a flashlight, and when you reach the end, the game goes to a "story frame" basically just text, and a button to play the next level.

The only problem is... i can't seem to destroy everything at the end of the frame, and then i get all sorts of errors and it wont run, I am trying to do all the code in the .fla so i can set up the game on screen instead of with coordinates and addChild, etc in the code.

can anyone help/have any suggestions

ActionScript Code:
stop(); var player_speed:int=2; var up,down,left,right:Boolean=false; var radius:int=8; addEventListener(Event.ENTER_FRAME,on_enter_frame); stage.addEventListener(KeyboardEvent.KEY_DOWN, on_key_down); stage.addEventListener(KeyboardEvent.KEY_UP, on_key_up); function on_enter_frame(e:Event):void {     if (up) {         player_mc.y-=player_speed;     }     if (down) {         player_mc.y+=player_speed;     }     if (left) {         player_mc.x-=player_speed;     }     if (right) {         player_mc.x+=player_speed;     }     if (player_mc.hitTestObject(next_mc)) {         gotoAndStop(2);         removeEventListener(Event.ENTER_FRAME,on_enter_frame);         stage.removeEventListener(KeyboardEvent.KEY_DOWN, on_key_down);         stage.removeEventListener(KeyboardEvent.KEY_UP, on_key_up);         /*removeChild(player_mc);         removeChild(next_mc);         removeChild(environment_mc);         removeChild(light_mc);*/     }     while (environment_mc.hitTestPoint(player_mc.x, player_mc.y+radius, true)) {         player_mc.y--;     }     while (environment_mc.hitTestPoint(player_mc.x, player_mc.y-radius, true)) {         player_mc.y++;     }     while (environment_mc.hitTestPoint(player_mc.x-radius, player_mc.y, true)) {         player_mc.x++;     }     while (environment_mc.hitTestPoint(player_mc.x+radius, player_mc.y, true)) {         player_mc.x--;     }     var dist_x:Number=player_mc.x-mouseX;     var dist_y:Number=player_mc.y-mouseY;     var angle:Number=- Math.atan2(dist_x,dist_y);     player_mc.rotation=to_degrees(angle);     light_mc.x=player_mc.x;     light_mc.y=player_mc.y;     light_mc.rotation=to_degrees(angle); } function on_key_down(e:KeyboardEvent):void {     switch (e.keyCode) {         case 37 :             left=true;             break;         case 38 :             up=true;             break;         case 39 :             right=true;             break;         case 40 :             down=true;             break;     } } function on_key_up(e:KeyboardEvent):void {     switch (e.keyCode) {         case 37 :             left=false;             break;         case 38 :             up=false;             break;         case 39 :             right=false;             break;         case 40 :             down=false;             break;     } } function to_radians(n:Number):Number {     return (n*0.0174532925); } function to_degrees(n:Number):Number {     return (n*57.2957795); }
Taytrefenwyd is offline   Reply With Quote
Old 11-03-2010, 11:48 PM   #2
Join Date: Dec 2008
Posts: 64

move the is code:
ActionScript Code:
if (player_mc.hitTestObject(next_mc)) {         gotoAndStop(2);         removeEventListener(Event.ENTER_FRAME,on_enter_frame);         stage.removeEventListener(KeyboardEvent.KEY_DOWN, on_key_down);         stage.removeEventListener(KeyboardEvent.KEY_UP, on_key_up);         removeChild(player_mc);         removeChild(next_mc);         removeChild(environment_mc);         removeChild(light_mc);     }

to the end of the on_enter_frame function and put the gotoAndPlay(2) at the end of the if statement and see if that helps.
bocasz is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:19 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.