3

i have a code which saves a display object locally as an image file, but at some point it began throwing error 2174. this code is called either from context-menu click event or keyboard event.

var sourceBmd:BitmapData = new BitmapData(displayObject.width,displayObject.height);            
sourceBmd.draw(displayObject,new Matrix(displayObject.width,0,0,displayObject.height));
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var byteArray:ByteArray = jpgEncoder.encode(sourceBmd);
try
{
    filereference.save(byteArray,"posterImage.jpg");    
}
catch (e:Error)
{
    Debugging.alert("error: ",e.message);           
}

as you can see, the filereference has only a single action - so no reason for error 2174 to be thrown. in case you wonder - i'm publishing for flash player 10.0

UPDATE: i found it it has to do with the flash player version: on 10.3 it works, while on 11.1 if fails.

any ideas? cheers, eRez

eRez
  • 257
  • 8
  • 24

3 Answers3

2

filereference.save needs to be called from a user action IE: mouse click
If it isn't you will get that error.
Also Publish for version 10 or higher.
Also per the docs.
Note that because of new functionality added to the Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save(). Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel() to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.

The_asMan
  • 6,364
  • 4
  • 23
  • 34
  • thanks, but it is being called from user interaction - either context menu click event or keyboard event - both produce the same erroand yes - i'm publishing for version 10. and yes, i also read that doc, so no - i don't have any other file reference active at the same time. – eRez Apr 03 '12 at 06:35
0

Does this link solve your problem?

Also, did you try restarting flash IDE after the error occurred?

loxxy
  • 12,990
  • 2
  • 25
  • 56
  • i ran into that link while searching for an answer. the problem occurs while working inside a browser, so i don't see how restarting the IDE would affect it – eRez Apr 03 '12 at 06:37
  • The reason I asked that you suddenly started getting the error is why I asked you to restart things. Often in flash communication, things don't really reflect a small change... – loxxy Apr 03 '12 at 07:04
0

by reading through the docs, i can assume:

  1. you're running in flash player 10
  2. you don't call filereference.cancel() in cases like when the user clicks "cancel" or "close" on the dialogue box that opens; try it
  • thanks, but i also read that doc, and i do call 'cancel()' when needed, however the problem occurs even if i don't click the cancel button – eRez Apr 03 '12 at 06:38
  • the only other suggestion i can come up with: grab the code from the part of **saving data to local files** from [here](http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cf8.html); try it with and without `fileRef.cancel()` in appropriate cases. Check whether they throw the same error. If it they do, then i'd be going into reinstalling players, browser plugins, IDE (voodoo dances - if it's Flash Builder). If they do not throw the error, i'd be checking the diff between your code and Adobe's. Is this the only place you actually use `FileReference` in your project? – Grigorash Vasilij Apr 03 '12 at 12:48