00:00
00:00
B1KMusic
Hi. I make games and software. I'm not on NG much, but feel free to peruse my youtube and gitlab for interesting stuff.

Braden @B1KMusic

Age 29, Male

Programmer/Musician/

fish

Earth, Milky Way

Joined on 6/19/11

Level:
10
Exp Points:
948 / 1,110
Exp Rank:
69,557
Vote Power:
5.20 votes
Rank:
Police Sergeant
Global Rank:
8,626
Blams:
42
Saves:
1,040
B/P Bonus:
12%
Whistle:
Normal
Medals:
799

Using one object for Savind, loading, deleting, and Keylistening! (Flash) (AS2 & AS3)

Posted by B1KMusic - July 27th, 2011


The following is a complete and total, as BomToons calls it, Nerdgasm, so if you don't use flash, or don't know what this is about, I suggest you turn away before your head explodes :D

This script was made in AS2, but it works in AS3, just as long as you change the code a bit.

The following code makes this flash movie tick, it saves two .SOL files on your computer, one called "Level" and the other called "Meta", as in information not seen by mortal eyes.

An object called "s" contains both shared objects, and acts as the key listener

an object called "ad" (Bottom of flash movie) is the object that gives info on where you can find the font (courtesy of me BTW, I spent 4 tireless hours working with that damn site drawing that font) M is an invisible white circle in the movie.

Controls:

+ adds to level
- takes away a level, in case you're sadistic

S prompts a Save
L prompts a Load
D prompts a Deletion

Y accepts prompts
N denies prompts

The following script goes into the frame:

ad._alpha = 0;
M._visible = false;
ad.onEnterFrame = function() {
ACX.FollowMouse(M);
if (M.hitTest(ad)) {
if (ad._alpha<100) {
ad._alpha += 25;
}
} else {
//if No hitTest
if (ad._alpha>0) {
ad._alpha -= 10;
}
}
};
//end info script
//START THE REST
var s = new Object();
s.L = SharedObject.getLocal("Level");
s.M = SharedObject.getLocal("Meta");
var Lvl = 0;
if (s.M.data.fileExists == true) {
savex.text = "Welcome Back, you can Continue your previous file by pressing \'L\'";
} else {
savex.text = "Welcome to the game, Press \'+\' or \'-\' to change level; you can save with \'S\' and delete with \'D\'";
}
function Save() {
s.L.data.Level = Lvl;
s.L.flush();
s.M.data.fileExists = true;
s.M.flush();
}
function Load() {
Lvl = s.L.data.Level;
}
function Delete() {
s.M.clear();
s.L.clear();
}
s.onKeyDown = function() {
KEY = Key.getCode();
if (KEY == key.PLUS) {
Lvl++;
savex.text = "Level: "+Lvl;
} else if (KEY == key.MIN) {
Lvl--;
savex.text = "Level: "+Lvl;
}//END LEVEL CHANGE
if (KEY == key.S) {
SP = true;
DP = false;
LP = false;
savex.text = "Save?";
} else if (KEY == key.D) {
DP = true;
SP = false;
LP = false;
savex.text = "Delete?";
} else if (KEY == key.L) {
LP = true;
SP = false;
DP = false;
savex.text = "Load?";
}//END SAVE, DELETE, and LOAD
if (SP == true || DP == true || LP == true) {
P = true;
}
//END PROMPT SCRIPT
if (KEY == key.Y) {
if (SP == true) {
SP = false;
P = false;
savex.text = "Saving . . . ";
Save();
if (!s.L.flush() || !s.M.flush()) {
savex.text = "Save Failed";
} else {
savex.text = "Save Successful";
}//END Y SAVE
} else if (DP == true) {
DP = false;
P = false;
savex.text = "Deleting . . . ";
Delete();
savex.text = "Delete Successful";
//END Y DELETE
} else if (LP == true) {
LP = false;
savex.text = "Loading . . . ";
if (!s.M.data.fileExists) {
s.M.data.fileExists = false;
savex.text = "No Save File Exists, Load Failed";
} else {
Load();
savex.text = "Load Successful";
}//END Y LOAD
}
//END Y
} else if (KEY == key.N && P == true) {
SP = false;
DP = false;
LP = false;
P = false;
savex.text = "Action Canceled";
}//END N
};
Key.addListener(s);

ACX.FollowMouse is part of a huge (400+ lines) Object Manipulating Class I made called "ACX". Here is the code for it, which you can't use in the frame, it must be in a seperate AS file

"key.S", "key.L" etc. are part of a class called "key", which is in a previous post

class ACX{
static function FollowMouse(obj, vis) {
var vis;
obj._x = _xmouse;
obj._y = _ymouse;
if (vis == false) {
Mouse.hide();
} else {
//reaching the conclusion of else means vis is true or undefined, so it can be left blank
Mouse.show();
}//ERROR CONSOLE (needs "m" and "ms" to work, comment if you want the code for some weird reason)
/*if (!obj) {
APICruft.objerr();
m("Tag: Mouse");
ms("obj: "+obj, "vis: "+vis);
}*/
}
}

Any questions, just comment. If the question is about why I posted this, the answer is 'Fuck off, I was bored.'


Comments

Comments ain't a thing here.