We help IT Professionals succeed at work.

Create simple loop

hzrdc2 asked
Last Modified: 2013-11-11
How can I get the attached code to loop forever?
var user:String;
var cpu:String;
user = userTxtField.text = "" + (Math.floor(Math.random() * 100000));
cpu = cpuTxtField.text = "" + (Math.floor(Math.random() * 100000));
	if (user == cpu){
		trace( user + " " + cpu + " = OMG! We Have A match!!!")
		trace( user + " " + cpu + " = No Match")

Open in new window

Watch Question

yes, but why? is that really a good idea?

var i:int;
your code
This one is on us!
(Get your first solution completely free - no credit card required)


I don't know if it is a good idea...? Basically, I want to see if I let this run for a couple days (locally), will I get a match. I am trying to see how random it really is...

your code worked, but flash puked with this error:

Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.      at random_test_fla::MainTimeline/random_test_fla::frame1()

Is there a way around this?
I dont think you can disable that via code, I did however find this page


which states "Just great; I forgot to mention HOW to set the timeout . Well here is how:
You cant set the timeoutperiod by code (neither in as3 nor in as2). You have to set the timeout manually in the publish settings of your fla: Ctrl+Shift+F12 > flash-tab > Script time limit.
Let me know if you still have trouble."
maybe use the setInterval and slow down the interval. I have an alarm clock I made in flash years ago that plays random MP3's on my computer as the alarm. It has intervals in there that check every 29 seconds. Maybe slow the interval down on your code to around every .1 seconds (100 milliseconds) or every 1/2 second (500)


I changed the script time limit to 60 and it still stops at 10,000 runs regardless.

I realize this is probably something flash was not intended to do and I am hitting some built in limit of the the output dialogue.

Is there a way to write directly to a file?


I'll just have it print if there was a match and call it done...

thanks MM

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.