Bits & Bytes

Posts Tagged ‘save’

How to Stop Losing Saved Flash Games

If you play Flash games with any frequency, you have probably noticed that, after a while, your saved games will disappear. Then you have to start the game from scratch and play through the entire game from the beginning again. Here, we show you how to fix this problem.

Expanding your browser’s cache does not prevent games from being erased. In fact, saved Flash games are stored in a location that is used across browsers. So, you can play the same game and continue your saved progress in any browser. However, you need to follow the steps below to prevent your saved games from being prematurely erased.

First, navigate to a page with a game on it, like this one.

Next, right-click inside the game window to bring up the context menu shown below and then left-click “Settings…” in the context menu.

This opens the Adobe Flash Player Settings dialog shown below. Left-click the “Local Storage” tab so that your settings dialog looks like the one below. Notice that the dialog asks how much storage xoax.net can use. This means that the storage is based on the website that you playing on, but not the game. By default, the value will be something small, like 10 kilobytes. With the default setting, the storage will run out fairly quickly, and you will lose all of your saved games, unless you increase the storage maximum.

To increase the storage, left-click and drag the slider to the right to increase the storage limit. I would recommend setting it to “Unlimited” so that you don’t have to worry about losing your progress. Note that you can see how much space is currently being used too. When you are done, left-click the close button and play some games!

Beware of clearing your browser’s cache. This may cause the Flash games to lose their storage, indirectly.

Saving a Screen Capture to a JPEG Image File in Actionscript 3.0

The program below demostrates how to capture an image of the stage and save it as a jpg image. We have drawn a yellow circle give the image capture something more interesting to render. To save the jpg image, just left-click the box above and select a location to save the image in.

The program for this jpg image capture is shown below. Additionally, you will need the JPGEncoder file which you can get here: https://github.com/mikechambers/as3corelib. To use the source file, select Edit->Preferences->Actionscript->Actionscript 3.0 Settings . . . and add the folder where you put “mikechambers-as3corelib-release.93-8-g24c6c16\mikechambers-as3corelib-24c6c16\src” to the src paths. Then you should be able to compile and execute the Actionscript code.

In this program, we import the JPGEncoder class and then draw a filled yellow circle on the stage. Next, we register an event listener to call the function SaveJPG() to save the image when a left-click occurs; Actionscript requires that file-saving code be contained in a user-initiated function.

Inside the callback, we create a BitmapData object that is the size of our stage and draw the stage into it. Then we create the encoder and call encode() to put the jpg data into a ByteArray. Finally, we create a FileReference object and save the jpg data.

import com.adobe.images.JPGEncoder;

// Draw a circle on the staqe
graphics.beginFill(0xFFFF00);
graphics.drawCircle(160, 120, 100);
graphics.endFill();

stage.addEventListener(MouseEvent.CLICK, SaveJPG);

function SaveJPG(e:MouseEvent):void {
	// Store the image capture of stage in a BitmapData Object
	var qImageData:BitmapData = new BitmapData(320, 240);
	qImageData.draw(stage);
	
	// Set the encoding to high-quality
	var qEncoder:JPGEncoder = new JPGEncoder(100);
	var qBytes:ByteArray = qEncoder.encode(qImageData);
	
	var qFile:FileReference = new FileReference();
	qFile.save(qBytes, "YellowCircle.jpg");
}
 

© 2007–2024 XoaX.net LLC. All rights reserved.