Flash FileReference, Uploading Larger Files, “A script in this movie is causing Flash Player to run slowly”

Tagged as: Flash

I realize my post titles may seem strange but I'm trying to make them as search engine friendly as possible.

With the advent of Flash 8 came file uploading capabilities. At the time we really weren't doing anything that had a calling for this lovely new capability. There were instances in the past where it would have been great, we tried all the tricks everyone else had and boy was it painful. Thankfully Macromedia listened and hooked us up! I love it when they do that.

Earlier this year the call came in and we needed the ability to upload video files from a Flash front end for a contest. Great! I said to myself, my boy Flash can do this. I skimmed the docs, prototyped a little test application and pushed it up to the server. Set the permissions on files and folders and we were ready to go!

The docs tell you that your supported up to around 100mb. Perfect, we have a 50mb cutoff for the videos, let's run some tests. Fire up the ole busted G4 or "Sweetness" as I call her and head back to the PC to start testing as "Sweetness" needs some serious ramp up time. Let's start out small, we'll upload a 3-4 mb file and see how it goes. Beautiful, all event handlers are firing, progress bar is functioning, complete event is called and the file is in the designated folder on the server ready to get worked.

Let's kick it up a notch and grab a 40mb file, we'll also fire up NetLimiter so we can bog down our connection a little bit. Start the upload and go grab a coffee. Upon returning i'm greeted with an error dialog I have only read about, I actually thought it was a myth:

"A script in this movie is causing Flash Player to run slowly"

Strange indeed, this is a bare bones prototype, no code outside of the FileReference event handlers other than a button that allows you to select a file and a progress bar that scales based on percentage up.

Let's see what sweetness has to say about this...

She's bombing in Safari on the 3-4mb file!

Turn off NetLimiter and re-try the 40mb file. File get's upped in a few minutes, no error messages. Rinse and repeat about 20 more times trying various sizes and speeds. Sometimes it generates an error sometimes it doesn't. Mind boggling to say the least. Mind you this isn't an IO, Security or HTTP Error, all server settings are proper, files and folders have rights, PHP is set to well over 500MB. It's just strange as it actually does go through sometimes.

Google searches return nothing, I found a few complaints about the same scenario but no one seems to have found a fix.

Adobe's KB article tells you it's a problem with the application, pointing to loading large amounts of data or manipulating large amounts of data and that the user might think the application is unresponsive. As with any downloading or uploading from within Flash you should always provide status to the user and I think most do. What I'm experiencing here doesn't seem to fall into this category though as users connection rates vary, this doesn't seem fair, why didn't they think about this?

So if Flash seems to think my simple prototype is unresponsive because it's taking too long to upload a largish file, then I need to give Flash some busy work while this is happening, in the form of a simple EnterFrame.

So now when we fire the FileReference.upload method we call another method that just increments an integer by 1 within an EnterFrame. Also we need to kill this process onComplete, onCancel and onAnyError.

Simply put, we need to startSomeNonsense and endSomeNonsense when we need to upload in Flash just to be safe. I'm also going to assume this is similar for the "download" portion of FileReference.

function startSomeNonsense
   var count:Number = 0;
   this.onEnterFrame = function(){
      count += 1;
   }
}
 
function endSomeNonsense
   delete this.onEnterFrame;
}
 
file.upload("file.php")
startSomeNonsense();

This seemed to get rid of the error dialog messages on all browsers and platforms ( mac / pc ) tested no matter what the transfer rate was, and this made me happy.

Note, this was tested with Flash Player 8 and early versions of Flash Player 9. Has not been tested with the latest version of Flash Player 9.

Hopefully this helps someone else in the future.

Posted by Mike on November 12th, 2007 at 6:00 pm

Nice, worked like a charm – thanks!

Posted by Harish on February 23rd, 2008 at 10:51 am

No word other than Great… – Thanks

Posted by Casey on February 29th, 2008 at 5:40 pm

You are a god among men, thank you kind sir!

Posted by Nilsch on April 1st, 2008 at 8:51 am

Found out that it’s not only the onEnterFrame function which can help us with this problem.

(Tested with CS3 – Flash 8 – AS 2)

Get the “publish settings”, go to the tab “flash”, then set the “script time limit” to a high number (1800 for example). It is measured in seconds.

This will also kill the “unresponsive” message.

Posted by Diogo Freire on May 14th, 2008 at 1:25 pm

Thanks so much for you guys. This stupid solution saved my life.

:)

Posted by Bro on May 15th, 2008 at 4:11 am

Whereas your startSomeNonsense() counts sheep, I think I’m going to make mine sing Beatles lyrics, just to keep itself entertained. Though, perhaps, “whistle while you work” is more suitable. Hi ho, hi ho.

Thank you for this solution, and the Google-friendly title!

Posted by David Gosnell on May 25th, 2008 at 12:09 pm

ok this seem like it would fix the problem with my dads computer..but I dont know where or how to insert the code to stop the error giving madness…and help in where and how I get to where I can enter the code?

Posted by JoeN on June 19th, 2008 at 10:26 am

Please post your paypal address.. I owe you…

Posted by Duncan on June 20th, 2008 at 12:12 am

Hi Joe, thanks for the offer, I do appreciate it! But I must respectfully decline. I’m just happy I’ve been able to help a few people keep some hair.

Posted by Unisda on June 28th, 2008 at 2:24 pm

thanks thank thank, you’ve saved my job. I’m preloading massive 2 – 5mb files and i occassionally get the error but the clients were understandably freaking out and i’ve been searching like crazy. thank you a whole lot.

Posted by Mrin on August 3rd, 2008 at 3:21 pm

Thanks!!!! Wooow, your solution -> BEST SOLUTION.
Thanks ;)

Posted by Ryan on September 2nd, 2008 at 2:22 pm

Dude you rock. I like your naming schemes… In an effort to help with your SEO efforts, I will post links to this page in other forums. Much appreciation.

~Ryan

Posted by Rrooll on October 2nd, 2008 at 9:28 am

IT WORKS, BIG THANKS!!!!! (CS3, AS2, Player9)

Posted by Bob on October 17th, 2008 at 8:51 am

Thanks man! Now I can have a nice weekend! :)

Posted by Dima on January 19th, 2009 at 12:47 pm

You rock man, your solution is perfectly working with Flash 10 using FileReferenceList to upload multiple files. I tried up to 250mb, works!

Thank you

Posted by Love on March 11th, 2009 at 4:53 pm

I dont know what’s wrong with my script! the “unresponsive” message is gone now. but I still can’t put large files in my upload_directory. But its working fine with smaller files. Im Just new to this. so pls help! thank you

Posted by zibra on August 30th, 2009 at 7:52 pm

Can’t believe, but it works! THX

Posted by Olivier on September 24th, 2009 at 7:10 am

Great tip ! it works wonderfully :)
It’s a shame to have to do such workarounds … Adobe developers could have used their brain a little more !
THANKS !

Posted by Dvirus on January 14th, 2010 at 3:04 pm

Thanks!

Posted by Simon on January 21st, 2010 at 10:20 am

Many thanks Duncan. You’ve just saved me a lot of grief and head-scratching.

Posted by Nissan on February 3rd, 2010 at 6:26 pm

Просто супер! Отлично! Будь собой.Дургие роли уже заняты

Posted by Народные средства on February 4th, 2010 at 1:38 pm

Хороший материал у вас тут опубликован, все интересно и грамотно изложено, за что вас благодарю. Пишите еще, я подписался на rss-ленту.

Posted by dave on March 3rd, 2010 at 11:30 am

ok this is how i fixed it ( sorry cant find orig link) go to “hippo file” download the flash uninstaller and the flash installer for IE also flash for non IE
Use Flash uninstaller restart pc to clear any .ocx then install flash and the other non IE
after this update your flash it worked for me
also try Secunia Personal Software Inspector
inspect your system for threats its fantastic

Posted by Nilton Bicalho on May 18th, 2010 at 3:55 pm

SMACK!!!!!! Thanks

Leave a comment