Friday, June 29, 2012

[Action Script] Can't copy file (SQLite) June,2012

I just wrote a simple AIR program using SQLite but can't seem to copy it (using Save As)

When the first square is pressed a number is multiplied by 1.5

When the second square is pressed the database is updated with the new number

The AIR program saves the number in the databank but the copied program doesn't

Am I going mad?





import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.data.SQLStatement;
import flash.data.SQLConnection;
import flash.filesystem.File;
import flash.events.SQLEvent;
import flash.net.Responder;
import flash.errors.SQLError;
import flash.data.SQLResult;


var ones2:Number = new Number();
ones2 = 1;

var but:Sprite = new Sprite();
but.graphics.beginFill(0x555555);
but.graphics.drawRect(0,0,40,40);
but.graphics.endFill();
but.x = 50;but.y = 50;
addChild(but);

var but2:Sprite = new Sprite();
but2.graphics.beginFill(0x555555);
but2.graphics.drawRect(0,0,40,40);
but2.graphics.endFill();
but2.x = 120;but2.y = 50;
addChild(but2);


but.addEventListener(MouseEvent.CLICK, butClick);
function butClick(event:MouseEvent):void
{
ones2 = ones2 * 1.5;
trace(ones2);
}


// ************************************************** **************************************


var connect:SQLConnection = new SQLConnection();

opendatabase();

function opendatabase():void
{
var testFile:File = File.applicationStorageDirectory.resolvePath("name File.db");
connect = new SQLConnection();
connect.addEventListener(SQLEvent.OPEN, onOpen);
connect.openAsync(testFile, SQLMode.CREATE);
}

function onOpen(SQLEvent):void
{
var stat:SQLStatement = new SQLStatement();
stat.sqlConnection = connect;
stat.text = "CREATE TABLE IF NOT EXISTS tester2 (id INTEGER PRIMARY KEY AUTOINCREMENT, one NUMERIC)";
stat.execute(-1, new Responder(onCreate, err));
}


function onCreate(SQLEvent):void
{
var stat:SQLStatement = new SQLStatement();
stat.sqlConnection = connect;
stat.text = "SELECT one FROM tester2 ORDER BY id";
stat.execute(-1, new Responder(onSelec, err));

}

function onSelec(event:SQLResult):void
{
if (event.data != null)
{
for (var i:int = 0;i<event.data.length;i++){
trace(event.data[i].one);
ones2 = event.data[i].one;
}
}
}

/* ******************
* *
* Button 2 *
* *
****************** */

but2.addEventListener(MouseEvent.CLICK, go1);
function go1(event:MouseEvent):void
{
var stat:SQLStatement = new SQLStatement();
stat.sqlConnection = connect;
stat.text = "UPDATE tester2 SET one = "+ones2+"";
stat.execute(-1,new Responder(onCreate,err));
}






function err(error:SQLError):void
{
trace(error.message);
trace(error.details);
}
Can't copy file (SQLite)

Related Post



0 comments: