Copy link to clipboard
Copied
Hi everyone! First I want to say I'm not very familiar with ac3.
I'm making a simple counter app, basically 1 buttons adds 1, another button adds 2 and another button adds 3. I have this variable (pts) that is the actuall data. What I want to do is to make it save the "pts" data so that its there the next time I open the file.
Here's what I have so far:
var pts:int=0
ptstxt.text = pts.toString();
//ptstxt is the text box that displays the pts value
but1.addEventListener(MouseEvent.CLICK, click_handler);
function click_handler(event_object:MouseEvent) {
pts += 1
trace(pts)
ptstxt.text = pts.toString();
}
//this button adds 1 to pts
but2.addEventListener(MouseEvent.CLICK, click_handler2);
function click_handler2(event_object:MouseEvent) {
pts += 2
trace(pts)
ptstxt.text = pts.toString();
}
//this button adds 2 to pts
I searched around and found that it would be for the best if I used the "shared object" but as my knowledge of ac3 isn't big I was unable to do it without help.
Also, would it be usable in an android app?
Looking forwad to a reply and thanks in advance.
:
...
var pts:int=0
var so:SharedObject=SharedObject.getLocal("counter","/");
if(so.data.count){
// do something with so.data.count which is the value of pts when your app was last used by the client computer.
}
ptstxt.text = pts.toString();
//ptstxt is the text box that displays the pts value
function saveCountF():void{
so.data.count=pts;
so.flush();
}
but1.addEventListener(MouseEvent.CLICK, click_handler);
function click_handler(event_object:MouseEvent) {
pts += 1
trace(pts)
ptstxt.t
Copy link to clipboard
Copied
:
var pts:int=0
var so:SharedObject=SharedObject.getLocal("counter","/");
if(so.data.count){
// do something with so.data.count which is the value of pts when your app was last used by the client computer.
}
ptstxt.text = pts.toString();
//ptstxt is the text box that displays the pts value
function saveCountF():void{
so.data.count=pts;
so.flush();
}
but1.addEventListener(MouseEvent.CLICK, click_handler);
function click_handler(event_object:MouseEvent) {
pts += 1
trace(pts)
ptstxt.text = pts.toString();
saveCountF();
}
//this button adds 1 to pts
but2.addEventListener(MouseEvent.CLICK, click_handler2);
function click_handler2(event_object:MouseEvent) {
pts += 2
trace(pts)
ptstxt.text = pts.toString();
saveCountF()
}
//this button adds 2 to pts
Copy link to clipboard
Copied
What exactly did you mean by "// do something with so.data.count which is the value of pts when your app was last used by the client computer.", I didn't quite understand... Should I replace the comment with some action or something?
Your help is appriciated!
Copy link to clipboard
Copied
yes, presumably you want to do something with that saved value. possibily you want to re-set pts to that saved value:
if(so.data.count)
pts=so.data.count;
}
Copy link to clipboard
Copied
Thank you! It works great!
Here's the code I used in case anybody needs it in the future:
var pts:int=0
var so:SharedObject=SharedObject.getLocal("counter","/");
if(so.data.count){
pts=so.data.count;
}
ptstxt.text = pts.toString();
//ptstxt is the text box that displays the pts value
function saveCountF():void{
so.data.count=pts;
so.flush();
}
but1.addEventListener(MouseEvent.CLICK, click_handler);
function click_handler(event_object:MouseEvent) {
pts += 1
ptstxt.text = pts.toString();
saveCountF();
}
//this button adds 1 to pts
but2.addEventListener(MouseEvent.CLICK, click_handler2);
function click_handler2(event_object:MouseEvent) {
pts += 2
ptstxt.text = pts.toString();
saveCountF()
}
//this button adds 2 to pts