Skip to main content
Inspiring
July 11, 2008
Question

Long loops

  • July 11, 2008
  • 12 replies
  • 705 views
Hi, I'm trying to export a MC to JPG format using PHP. The procedure calls for a nested loop which reads each pixel and catenates its color value in an array in order to be sent to PHP.

After the loop runs for a few seconds, I get the "Flash running slow" message .How can I avoid this and make sure Flash doesn't think I've entered a neverending loop?

Furthermore, I have a ProgressBar component which measures the amount of data analyzed. Unfortunately, the ProgressBar doesn't appear until AFTER the loop has finished running.

I'm used to programming in VB6 where a functions called DoEvents placed inside a loop allows the language engine to execute all background procedures and not think I've entered an endless loop. This also allows for screen and progress refreshes. Is there something similar in Flash?

Here is my code:
This topic has been closed for replies.

12 replies

kglad
Community Expert
Community Expert
July 21, 2008
you're not going to get the stage to update (and display a progress bar or anything else) unless you break the processing into loops like i explained above.
Inspiring
July 21, 2008
You could use the BitMapData class and cut the graphic up into chunks. Then it would be running on smaller graphics. You do one chunk then update your progress bar and start it again for the next chunk. I would imagine if you divided it up into 8 or so pieces that should make it work?

As for keeping the user from clicking on things while it runs, the simplest solution is to not give them anything to click on while it is running.

During a loop you won't get screen updates. That is the issue at hand here. When you have some code, all the code on that frame needs to execute before the screen is updated. If the code takes too long to execute the screen won't execute and you get the error message that a script is making Flash run slowly.

tatiana1Author
Inspiring
July 21, 2008
True, but I'd like to eliminate the problem at its root. If I increase the timeout duration, it may work fine for my PC, but it might not work for someone else's. I'd like to simply eradicate the problem by not making Flash think the loop is infinite.

Furthermore, I placed a ProgressBar within the loop to indicate the export progress, but it doesn't even show up on the screen. As a matter of fact, during the loop, the screen never refreshes. I even put an Invalidate command within the loop, but no go. Do you have any ideas? Thank you.
kglad
Community Expert
Community Expert
July 21, 2008
in your publish settings you can adjust the default timeout duration of 15 seconds: file/publish setting/flash/script timout limit
kglad
Community Expert
Community Expert
July 20, 2008
did you change your publish settings?

and you can break your double for-loop into one for-loop that's called (up to) 1280 times using and onEnterFrame or setInterval() loop.
tatiana1Author
Inspiring
July 20, 2008
What do you mean when you say "did you change your publish settings"? How should I change them?

Can you give me an idea of how to change the double 'for' loop into a setInterval - type of loop? If I use setInterval, how do I keep the user from clicking other things while the loop is going?
tatiana1Author
Inspiring
July 19, 2008
Hi, I tried the BitmapExporter and a whole slew of other dandy methods and they all work well on small pictures. Unfortunately, I'm dealing with pictures which can be as large as 1280x1280 pixels! After only a few seconds of processing, Flash tells me the script is running too slow. I read somewhere that the routine could be spread out over several frames in order to fool Flash into thinking that everything is running normally, but I haven't the faintest idea as to how to do it. Can anyone help me??? I'm stuck!!!
kglad
Community Expert
Community Expert
July 14, 2008
you can't use any as3 classes with as2 code.

you can check mario klingemann's bitmapexporter class which has image scan methods that speed processing.
tatiana1Author
Inspiring
July 14, 2008
Thanks for your replies.

I'm wondering if there's a better approach to saving MC as a JPG. A thought came up: if I'm using AS2, can I call an AS3 procedure that does the job, so that I can use the ByteArray class?

If they do exist, do you have any idea what other methods I could use to do what I need to do, using only AS2 classes? I've searched around, but came up with nothing. It surprises me that Flash allows you to export an image from the stage when in the development environment, but it doesn't allow you to do the same thing dynamically from AS2.
kglad
Community Expert
Community Expert
July 11, 2008
oh man. i'm sorry.

i knew i might goof that up. i tried to google that to get credit where it was due but didn't find the reference i wanted and i didn't have more than a few minutes to search.

i edited my message to correct that.
Inspiring
July 11, 2008
That's my array compressor actually. :)

--
Dave -
www.offroadfire.com
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/