Reputation: 257
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
Upvotes: 3
Views: 1377
Reputation: 6403
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.
Upvotes: 2
Reputation: 713
by reading through the docs, i can assume:
filereference.cancel()
in cases like when the user clicks "cancel" or "close" on the dialogue box that opens; try itUpvotes: 0