Home Tutorials Forums Articles Blogs Movies Library Employment Press

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

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-11-2012, 04:30 PM   #1
OwlShield
Registered User
 
Join Date: Jul 2012
Posts: 3
Default [AS2] While+Hittest Help

Hi,

While I was making menu of my new game, I take this problem in Flash 8.

Flash 8 says :

A script in this movie is causing Flash Player to run slowly. If it continues to run, your computer may become unresponsive.Do you want to abort the script.

Yes or No.

I think, this problem from my using while and hittest. Where I make mistake ?

Codes :

Code:
credits._visible = false;
howtoplay._visible = false;
onEnterFrame = function () {
	while (man.hitTest(button1)) {
		if (Key.isDown(Key.ENTER)) {
			credits._visible = true;
		}
	}
	while (man.hitTest(button2)) {
		if (Key.isDown(Key.ENTER)) {
			howtoplay._visible = true;
		}
	}
	while (man.hitTest(button3)) {
		if (Key.isDown(Key.ENTER)) {
			gotoAndStop("Tanitim", 1);
		}
	}
	while (man.hitTest(quitbutton)) {
		if (Key.isDown(Key.ENTER)) {
			fscommand("quit", true);
		}
	}
};
credits = Movie Clip
howtoplay = Movie Clip
man = Movie Clip
And all buttons are movie clip.
Where is problem ?

Sorry for my bad English.

Last edited by OwlShield; 07-11-2012 at 08:00 PM.
OwlShield is offline   Reply With Quote
Old 07-17-2012, 12:01 AM   #2
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,183
Default

An enterframe function will fire all the lines just once at in each time the flash renders the screen. But the "while" command will loop before rendering a frame. So if something inside of the "while" loop is depending on the happenings on the screen you will get an eternal loop if you don't change those screen happenings inside of the while loop. That's why your debugger is giving you a warning. or to be more precise if the loop at the single rendering time takes longer than a 15 seconds or so then you will get a warning

So maybe something like this could work:

ActionScript Code:
credits._visible = false; howtoplay._visible = false; // buttons in array var buttons:Array = [button1, button2, button3, quitbutton]; onEnterFrame = function () {     // loop through the buttons to hittest     for(var i:Number = 0; i < buttons.length; i++)     {         // hitTest and check if the key enter is down         if (man.hitTest(buttons[i]) && Key.isDown(Key.ENTER))         {             // and now depending on which button or as             // I have here which index number of a button             // is active do what needs to be bone...             switch(i)             {                 case 0 :                     credits._visible = true;                     break;                 case 1 :                     howtoplay._visible = true;                     break;                 case 2 :                     gotoAndStop("Tanitim", 1);                     break;                 case 3 :                     fscommand("quit", true);                     break;                 default :                     break;             }         }     } };
-:)lauri is offline   Reply With Quote
Reply


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 10:28 AM.

///
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.