Bits & Bytes

Posts Tagged ‘play’

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.

Loading and Playing a Sound File in Actionscript 3.0

This program loads an mp3 file and plays it. The entire program is given below and the compiled SWF is shown above. To hear the file play, left-click the window above.

The code begins with three lines that tell the user to click the screen. Then we create a String for the URL, which could also be a local file. Next, we set our function as the callback for mouse clicks. Inside the function OnClick(), we create a Sound object, load the sound file, and then play it.

// Output the initial instructions to user
var qInstructions:TextField = new TextField();
qInstructions.text = "Click To Play";
addChild(qInstructions);

const ksXoaXDotNet:String = "http://www.xoax.net/public/XoaXDotNet.mp3";

// Play the mp3 when the screen is clicked
stage.addEventListener(MouseEvent.CLICK, OnClick);

function OnClick(e:MouseEvent): void {
	var qSound:Sound = new Sound();
	qSound.load(new URLRequest(ksXoaXDotNet));
	qSound.play();
}

Playing a Video File in Actionscript 3.0

We begin by creating an Actionscript 3.0 project and setting the stage dimensions to match our video. In this case, the video is 240 by 180 pixels. Then we add this code, compile, and execute. To play the video file, click the screen as shown above.

// Output the initial instructions to user
var qInstructions:TextField = new TextField();
qInstructions.text = "Click To Play";
addChild(qInstructions);

// Create a video object with 240x180 pixels
var MyVideo:Video = new Video(240, 180);
addChild(MyVideo);

var qNetConnection:NetConnection = new NetConnection();
qNetConnection.connect(null);

var qNetStream:NetStream = new NetStream(qNetConnection);
MyVideo.attachNetStream(qNetStream);
// Add this line to ignore metadata and cue points
qNetStream.client = new Object();

// Play the video when the screen is clicked
stage.addEventListener(MouseEvent.CLICK, OnClick);
function OnClick(e:MouseEvent): void {
	qNetStream.play("http://xoax.net/public/XoaX.flv");
}

The first part of the program outputs the message telling the user to click the screen. Next, we create a Video object that matches the dimensions of our video. Then we create a NetConnection object and call connect() with the argument value null to signal that we are going to load a sound or video file. Finally, we create a NetStream object using the NetConnection and attach it to the Video.

Once this is done, we can play a video file from anywhere: either our local drive or a remote location on the web. To make the video wait to play until the user clicks, we have wrapped the call to play() in a callback that is called when the stage is clicked.