Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Im new to Actionscript 3.. when i clicked the green circle it turns into red and i want it to stay that way?

New Here ,
Apr 24, 2015 Apr 24, 2015

Im new to Actionscript 3.. when i clicked the green circle it turns into red and i want it to stay that way but it wont saved.I dont know but the color wont saved help anyone?... but its flushing.

the instance name for the movie clip is green


heres the source code

var myS:SharedObject = SharedObject.getLocal("sdsds");

var my_color:ColorTransform = new ColorTransform();

my_color.color = 0xFF0000;

green.object = myS.data.me;

green.addEventListener(MouseEvent.CLICK... myClick);

function myClick (e:MouseEvent):void{

trace("I was clicked!");

green.transform.colorTransform = my_color;

trace(myS.flush());

}

trace(myS.data.me);

TOPICS
ActionScript
796
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 24, 2015 Apr 24, 2015

use:

var myS:SharedObject = SharedObject.getLocal("sdsds",'/');

var my_color:ColorTransform = new ColorTransform();

my_color.color = 0xFF0000;

if(myS.data.my_color){
green.transform.colorTransform=my_color;
}

green.addEventListener(MouseEvent.CLICK,myClick);

function myClick (e:MouseEvent):void{

green.transform.colorTransform = my_color;

myS.data.my_color=true;

}

Translate
Community Expert ,
Apr 24, 2015 Apr 24, 2015

use:

var myS:SharedObject = SharedObject.getLocal("sdsds",'/');

var my_color:ColorTransform = new ColorTransform();

my_color.color = 0xFF0000;

if(myS.data.my_color){
green.transform.colorTransform=my_color;
}

green.addEventListener(MouseEvent.CLICK,myClick);

function myClick (e:MouseEvent):void{

green.transform.colorTransform = my_color;

myS.data.my_color=true;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2015 Apr 24, 2015

thank you so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2015 Apr 24, 2015

can you tell me how to make it a save file in flash  so it can trace it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 24, 2015 Apr 24, 2015

what do you mean by, 'a save file'?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2015 Apr 26, 2015

I mean i want it to have a something like cookie. so that i can call it anytime.. and the last coor it change will be saved

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2015 Apr 26, 2015

that's what you're doing with that sharedobject.  i showed the code on how to use that to remember the color change.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2015 Apr 27, 2015

okay thanks ... so much youre a big help.. can you also teach me database on flash.. i need it for my thesis thats why im practicing... Were creating a map app with database. example is in the data wherein the user will input a number. when the number reach the critical point the map will become red but if not it is green. it would be a big help thnx

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2015 Apr 27, 2015

are you making an air application or a web-based (something that will be displayed in a browser and saved on a file server) application?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2015 Apr 27, 2015

its a stand alone app sir kglad

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2015 Apr 27, 2015

for air database use, actionscript has the sql classes.  the main one to start with is sqlconnection.

go here and bookmark this page (or even better download the files), Adobe ActionScript® 3 (AS3) API Reference

check the sql classes.

p.s. i found this tool very helpful during debugging, SQLite Administrator - International Milestone Beta but you should google sqlite management tools to see what works best for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2015 Apr 27, 2015

what file would i download in the bookmark page you told me?.... where would i create the database is it in the sqlite administrator?.. thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2015 Apr 27, 2015

click the 2nd link (zip file, standalone.zip) from here ActionScript reference archive | Adobe Developer Connection

extract it to a directory and then create a shortcut to index.html

don't create the datebase use sqliteadmin.  create it using actionscript just like your users.  you'll create, add, delete etc everything using actionscript using the app you're creating.  sqladmin is just so you can see what you're doing and help you debug your actionscript.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2015 Apr 27, 2015

what code do I use in actionscrpt is it    "sql" or "actionscript" ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2015 Apr 27, 2015

here's sample code from a project i did:

import flash.data.SQLConnection;

import flash.data.SQLStatement;

import flash.events.SQLErrorEvent;

import flash.events.SQLEvent;

import flash.filesystem.File;

// assign savedDesignsA when loads

import as3.com.hexagonstar.util.debug.Debug;

function traceF(s:String){

    Debug.trace(s);

}

var savedDesignsA:Array;

var sqlConn:SQLConnection = new SQLConnection();

sqlConn.addEventListener(SQLEvent.OPEN, openHandler);

sqlConn.addEventListener(SQLErrorEvent.ERROR, errorHandler);

var dbFile:File = File.applicationStorageDirectory.resolvePath("smPrintEstimateDB.db");

    // SQLMode.CREATE is default openAsync 2nd parameter which creates db if doesn't exist and opens it for updating if it does exist

    // traceF(dbFile.nativePath);

sqlConn.openAsync(dbFile);

function openHandler(event:SQLEvent):void {

    //traceF("the database was created successfully");

    createTableF();

}

function errorHandler(event:SQLErrorEvent):void {

    traceF("Error message: "+event.error.message);

    traceF("Details: "+event.error.details);

}

//****************** begin create table ***********************************

function createTableF(){

    var createStmt:SQLStatement = new SQLStatement();

    createStmt.sqlConnection = sqlConn;

    var sql:String = 

        "CREATE TABLE IF NOT EXISTS docks ( dockId INTEGER PRIMARY KEY AUTOINCREMENT, dockName TEXT, dataS TEXT)";

    createStmt.text = sql;

    createStmt.addEventListener(SQLEvent.RESULT, createResult);

    createStmt.addEventListener(SQLErrorEvent.ERROR, createError);

    createStmt.execute();

}

function createResult(event:SQLEvent):void {

    //traceF("Table created");

    // query db for dockId, dockName

    selectDataF("SELECT dockId, dockName, dataS FROM docks");

}

function createError(event:SQLErrorEvent):void {

    traceF("Error message: "+event.error.message);

    traceF("Details: "+event.error.details);

}

//****************** end create table ************************************

//

//

//****************** begin insert data ***********************************

function insertDataF(dockname:String,dbString:String){

    var insertStmt:SQLStatement = new SQLStatement();

    insertStmt.sqlConnection = sqlConn;

    /*

    stmt.text = "INSERT INTO pages (title, content) VALUES (?, ?)"

    var sql:String = "INSERT INTO employees (firstName, lastName, salary) VALUES ('Bob', 'Smith', 8000)";

    */

    //stmt.text = "SELECT col1,col2 FROM table WHERE col1= :param2"

    //stmt.parameters[":param2"] = "whatever"

   

    var sql:String = "INSERT INTO docks (dockName,dataS) VALUES (:param1,:param2)";

   

    insertStmt.text = sql;

    insertStmt.parameters[":param1"] = dockname;

    insertStmt.parameters[":param2"] = dbString;

    // register listeners for the result and failure (status) events

    insertStmt.addEventListener(SQLEvent.RESULT, insertResult);

    insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);

    // execute the statement

    insertStmt.execute();

}

function insertResult(event:SQLEvent):void {

    //traceF("INSERT statement succeeded");

    insertResultToAppF("success");

}

function insertError(event:SQLErrorEvent):void{

    traceF("Error message: "+event.error.message);

    traceF("Details: "+event.error.details);

    insertResultToAppF(event.error.message+"\n"+event.error.details);

}

//****************** end insert data ********************************************

//****************** begin update/change data ***********************************

function updateDataF(sql:String){

    var updateStmt:SQLStatement = new SQLStatement();

    updateStmt.sqlConnection = sqlConn;

    /*

    'UPDATE city SET processing=:amount WHERE id=:city'

    UPDATE [OR conflict-algorithm] [database-name.] table-name SET assignment [, column-name = expr]* [WHERE expr]

    */

    updateStmt.text = sql;

    // register listeners for the result and failure (status) events

    updateStmt.addEventListener(SQLEvent.RESULT, updateResult);

    updateStmt.addEventListener(SQLErrorEvent.ERROR, updateError);

    // execute the statement

    updateStmt.execute();

}

function updateResult(event:SQLEvent):void {

    traceF("update statement succeeded");

}

function updateError(event:SQLErrorEvent):void{

    traceF("Error message: "+event.error.message);

    traceF("Details: "+event.error.details);

}

//****************** end update/change data ***********************************

//****************** begin delete data ****************************************

function deleteDataF(dockID:int){

    var deleteStmt:SQLStatement = new SQLStatement();

    deleteStmt.sqlConnection = sqlConn;

   

    //stmt.text = "SELECT col1,col2 FROM table WHERE col1= :param2"

    //stmt.parameters[":param2"] = "whatever"

   

    var sqlDelete:String = "DELETE from docks WHERE dockId= :param";

    //DELETE FROM [database-name.] table-name [WHERE expr]

    //"DELETE from docks WHERE firstname='"+user.firstname+"' and lastname='"+user.lastname+"' and email='"+user.email+"';";

    deleteStmt.text = sqlDelete;

    deleteStmt.parameters[":param"] = dockID;

    // register listeners for the result and failure (status) events

    deleteStmt.addEventListener(SQLEvent.RESULT, deleteResult);

    deleteStmt.addEventListener(SQLErrorEvent.ERROR, deleteError);

    // execute the statement

    deleteStmt.execute();

}

function deleteResult(event:SQLEvent):void {

    //traceF("delete statement succeeded");

    deleteResultCS4ToAppF("success");

}

function deleteError(event:SQLErrorEvent):void{

    traceF("Error message: "+event.error.message);

    traceF("Details: "+event.error.details);

    deleteResultCS4ToAppF(event.error.message+"\n"+event.error.details);

}

//****************** end delete data *************************************

//

//****************** begin select data ***********************************

function selectDataF(sql:String){

    var selectStmt:SQLStatement = new SQLStatement();

    selectStmt.sqlConnection = sqlConn;

    /*

    "SELECT dockId, dockName FROM docks"

    "SELECT itemId, itemName, price FROM products";

    stmt.text = "SELECT content FROM pages WHERE id = ?";

    stmt.text = "SELECT col1,col2 FROM table WHERE col1= :param2"

    stmt.parameters[":param2"] = "whatever"

    SELECT [ALL | DISTINCT] result [FROM table-list] [WHERE expr] [GROUP BY expr-list] [HAVING expr] [compound-op select-statement]* [ORDER BY sort-expr-list] [LIMIT integer [( OFFSET | , ) integer]]

    */

    selectStmt.text = sql;

    // register listeners for the result and failure (status) events

    selectStmt.addEventListener(SQLEvent.RESULT, selectResult);

    selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);

    // execute the statement

    selectStmt.execute();

}

function selectResult(event:SQLEvent):void {

    var selectStmt:SQLStatement = SQLStatement(event.currentTarget);

    var result:SQLResult = selectStmt.getResult();

    // reinitialize savedDesignsA whenever database queried for all designs

    savedDesignsA = [];

    if(result.data != null){

        var numResults:int = result.data.length;

        for (var i:int = 0; i < numResults; i++){

            var row:Object = result.data;

            //var output:String = "dockId: " + row.dockId;

            //output += "; dockName: " + row.dockName;

            //output += "; dockS: " + row.dataS;

            savedDesignsA.push([row.dockId,row.dockName,row.dataS]);

            //traceF(output);

            // don't send when first loaded because app.swf not ready.  thereafter (when a new design is saved), can send savedDesignsA immediately

        }

        if(send_savedDesignNow){

            send_savedDesignsA_toAppF();

        }

    }

}

function selectError(event:SQLErrorEvent):void{

    traceF("Error message: "+event.error.message);

    traceF("Details: "+event.error.details);

}

//****************** end select data ***********************************

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2015 Apr 27, 2015

Sir  can I request for a sample of a simple circle movieclip when clicked will become red based on a number. it's okay if its not.. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2015 Apr 27, 2015

so when making the database . Im gonna create the table using sqliteadmin and then code it in actionscript? im gonna connect the table to the sqlliteaadmin?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2015 Apr 28, 2015

no.

ignore the comments about sqliteadmin and don't use sqliteadmin.  it's just confusing you.

if(somevar>somenumber){
simplecircle.transform.colorTransform=0xff0000;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2015 Apr 28, 2015

I have a question. Where did you get the stmt.text? it is a variable or the name of a text field. Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2015 Apr 28, 2015

it's an on-stage textfield to give the user feedback.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

kglad thnx for always replying. Right now my groupmate is reviewig on how to code the database he was the one who ask on the last reply.

we still dot know where to code weve been searching for a tutorial on youtube.

Can you tells us where?

heres what i do.

1) Open adobe flash professional cs6

2) Create new adobe air

3) where do we code now? thnx

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2015 Apr 30, 2015

database coding is for intermediate-advanced actionscripters.  it's not a good place to start if you're just leaning.

the forums are a good place to ask for general direction help and for specific issues.  but you won't get me or anyone else to run through all the code or even all the major steps involved in creating an air project when you don't know the basics.

you should start with the flash basics before you start this project.  i suggest trevor mccauley's tutorials: senocular.com - Flash Tutorials

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Im working on my project now. I'm trying to add data in database using a text field and when you click the save button the data from the text field will be added to the database.

Here is the code:

import fl.data.DataProvider;

adddata.png

import flash.data.SQLResult;

import flash.data.SQLConnection;

import flash.filesystem.File;

import flash.data.SQLStatement;

import flash.data.SQLConnection;

var conn:SQLConnection;

var createStmt:SQLStatement;

var insertStmt:SQLStatement;

var insertStmt2:SQLStatement;

var insertStmt3:SQLStatement;

var selectStmt:SQLStatement;

var insert1Complete:Boolean = false;

var insert2Complete:Boolean = false;

loadBtn.addEventListener(MouseEvent.CLICK, getData);

init();

function init():void

{

  conn = new SQLConnection();

  conn.addEventListener(SQLEvent.OPEN, openSuccess);

  conn.addEventListener(SQLErrorEvent.ERROR, openFailure);

  status.text = "Creating and opening database";

  // Use these two lines for an on-disk database

  // but be aware that the second time you run the app you'll get errors from

  // creating duplicate records.

// var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");

// conn.openAsync(dbFile);

  // Use this line for an in-memory database

  conn.openAsync(null);

}

function openSuccess(event:SQLEvent):void

{

  conn.removeEventListener(SQLEvent.OPEN, openSuccess);

  conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

  createTable();

}

function openFailure(event:SQLErrorEvent):void

{

  conn.removeEventListener(SQLEvent.OPEN, openSuccess);

  conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

  status.text = "Error opening database";

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

function createTable():void

{

  status.text = "Creating table";

  createStmt = new SQLStatement();

  createStmt.sqlConnection = conn;

  var sql:String = "";

  sql += "CREATE TABLE IF NOT EXISTS employees (";

  sql += " empId INTEGER PRIMARY KEY AUTOINCREMENT,";

  sql += " firstName TEXT,";

  sql += " lastName TEXT,";

  sql += " salary NUMERIC CHECK (salary >= 0) DEFAULT 0";

  sql += ")";

  createStmt.text = sql;

  createStmt.addEventListener(SQLEvent.RESULT, createResult);

  createStmt.addEventListener(SQLErrorEvent.ERROR, createError);

  createStmt.execute();

}

function createResult(event:SQLEvent):void

{

  createStmt.removeEventListener(SQLEvent.RESULT, createResult);

  createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);

  addData();

}

function createError(event:SQLErrorEvent):void

{

  status.text = "Error creating table";

  createStmt.removeEventListener(SQLEvent.RESULT, createResult);

  createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);

  trace("CREATE TABLE error:", event.error);

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

function addData():void

{

  status.text = "Adding data to table";

  insertStmt = new SQLStatement();

  insertStmt.sqlConnection = conn;

  var sql:String = "";

  sql += "INSERT INTO employees (firstName, lastName, salary) ";

  sql += "VALUES ('Bob', 'Smith', 8000)";

  insertStmt.text = sql;

  insertStmt.addEventListener(SQLEvent.RESULT, insertResult);

  insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);

  insertStmt.execute();

  insertStmt2 = new SQLStatement();

  insertStmt2.sqlConnection = conn;

  var sql2:String = "";

  sql2 += "INSERT INTO employees (firstName, lastName, salary) ";

  sql2 += "VALUES ('John', 'Jones', 8200)";

  insertStmt2.text = sql2;

  insertStmt2.addEventListener(SQLEvent.RESULT, insertResult);

  insertStmt2.addEventListener(SQLErrorEvent.ERROR, insertError);

  insertStmt2.execute();

}

function insertResult(event:SQLEvent):void

{

  var stmt:SQLStatement = event.target as SQLStatement;

  stmt.removeEventListener(SQLEvent.RESULT, insertResult);

  stmt.removeEventListener(SQLErrorEvent.ERROR, insertError);

  if (stmt == insertStmt)

  {

  insert1Complete = true;

  }

  else

  {

  insert2Complete = true;

  }

  if (insert1Complete && insert2Complete)

  {

  status.text = "Ready to load data";

  }

}

function insertError(event:SQLErrorEvent):void

{

  status.text = "Error inserting data";

  insertStmt.removeEventListener(SQLEvent.RESULT, insertResult);

  insertStmt.removeEventListener(SQLErrorEvent.ERROR, insertError);

  trace("INSERT error:", event.error);

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

function getData(event:MouseEvent):void

{

  status.text = "Loading data";

  selectStmt = new SQLStatement();

  selectStmt.sqlConnection = conn;

  var sql:String = "SELECT empId, firstName, lastName, salary FROM employees";

  selectStmt.text = sql;

  selectStmt.addEventListener(SQLEvent.RESULT, selectResult);

  selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);

  selectStmt.execute();

}

function selectResult(event:SQLEvent):void

{

  status.text = "Data loaded";

  selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);

  selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);

  var result:SQLResult = selectStmt.getResult();

  resultsGrid.dataProvider = new DataProvider(result.data);

// var numRows:int = result.data.length;

// for (var i:int = 0; i < numRows; i++)

// {

// var output:String = "";

// for (var prop:String in result.data)

// {

// output += prop + ": " + result.data[prop] + "; ";

// }

// trace("row[" + i.toString() + "]\t", output);

// }

}

function selectError(event:SQLErrorEvent):void

{

  status.text = "Error loading data";

  selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);

  selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);

  trace("SELECT error:", event.error);

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

import fl.data.DataProvider;

import flash.data.SQLResult;

import flash.data.SQLConnection;

import flash.filesystem.File;

import flash.data.SQLStatement;

import flash.data.SQLConnection;

var conn:SQLConnection;

var createStmt:SQLStatement;

var insertStmt:SQLStatement;

var insertStmt2:SQLStatement;

var insertStmt3:SQLStatement;

var selectStmt:SQLStatement;

var insert1Complete:Boolean = false;

var insert2Complete:Boolean = false;

loadBtn.addEventListener(MouseEvent.CLICK, getData);

init();

function init():void

{

  conn = new SQLConnection();

  conn.addEventListener(SQLEvent.OPEN, openSuccess);

  conn.addEventListener(SQLErrorEvent.ERROR, openFailure);

  status.text = "Creating and opening database";

  // Use these two lines for an on-disk database

  // but be aware that the second time you run the app you'll get errors from

  // creating duplicate records.

// var dbFile:File = File.applicationStorageDirectory.resolvePath("DBSample.db");

// conn.openAsync(dbFile);

  // Use this line for an in-memory database

  conn.openAsync(null);

}

function openSuccess(event:SQLEvent):void

{

  conn.removeEventListener(SQLEvent.OPEN, openSuccess);

  conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

  createTable();

}

function openFailure(event:SQLErrorEvent):void

{

  conn.removeEventListener(SQLEvent.OPEN, openSuccess);

  conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);

  status.text = "Error opening database";

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

function createTable():void

{

  status.text = "Creating table";

  createStmt = new SQLStatement();

  createStmt.sqlConnection = conn;

  var sql:String = "";

  sql += "CREATE TABLE IF NOT EXISTS employees (";

  sql += " empId INTEGER PRIMARY KEY AUTOINCREMENT,";

  sql += " firstName TEXT,";

  sql += " lastName TEXT,";

  sql += " salary NUMERIC CHECK (salary >= 0) DEFAULT 0";

  sql += ")";

  createStmt.text = sql;

  createStmt.addEventListener(SQLEvent.RESULT, createResult);

  createStmt.addEventListener(SQLErrorEvent.ERROR, createError);

  createStmt.execute();

}

function createResult(event:SQLEvent):void

{

  createStmt.removeEventListener(SQLEvent.RESULT, createResult);

  createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);

  addData();

}

function createError(event:SQLErrorEvent):void

{

  status.text = "Error creating table";

  createStmt.removeEventListener(SQLEvent.RESULT, createResult);

  createStmt.removeEventListener(SQLErrorEvent.ERROR, createError);

  trace("CREATE TABLE error:", event.error);

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

function addData():void

{

  status.text = "Adding data to table";

  insertStmt = new SQLStatement();

  insertStmt.sqlConnection = conn;

  var sql:String = "";

  sql += "INSERT INTO employees (firstName, lastName, salary) ";

  sql += "VALUES ('Bob', 'Smith', 8000)";

  insertStmt.text = sql;

  insertStmt.addEventListener(SQLEvent.RESULT, insertResult);

  insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);

  insertStmt.execute();

  insertStmt2 = new SQLStatement();

  insertStmt2.sqlConnection = conn;

  var sql2:String = "";

  sql2 += "INSERT INTO employees (firstName, lastName, salary) ";

  sql2 += "VALUES ('John', 'Jones', 8200)";

  insertStmt2.text = sql2;

  insertStmt2.addEventListener(SQLEvent.RESULT, insertResult);

  insertStmt2.addEventListener(SQLErrorEvent.ERROR, insertError);

  insertStmt2.execute();

}

function insertResult(event:SQLEvent):void

{

  var stmt:SQLStatement = event.target as SQLStatement;

  stmt.removeEventListener(SQLEvent.RESULT, insertResult);

  stmt.removeEventListener(SQLErrorEvent.ERROR, insertError);

  if (stmt == insertStmt)

  {

  insert1Complete = true;

  }

  else

  {

  insert2Complete = true;

  }

  if (insert1Complete && insert2Complete)

  {

  status.text = "Ready to load data";

  }

}

function insertError(event:SQLErrorEvent):void

{

  status.text = "Error inserting data";

  insertStmt.removeEventListener(SQLEvent.RESULT, insertResult);

  insertStmt.removeEventListener(SQLErrorEvent.ERROR, insertError);

  trace("INSERT error:", event.error);

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

function getData(event:MouseEvent):void

{

  status.text = "Loading data";

  selectStmt = new SQLStatement();

  selectStmt.sqlConnection = conn;

  var sql:String = "SELECT empId, firstName, lastName, salary FROM employees";

  selectStmt.text = sql;

  selectStmt.addEventListener(SQLEvent.RESULT, selectResult);

  selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);

  selectStmt.execute();

}

function selectResult(event:SQLEvent):void

{

  status.text = "Data loaded";

  selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);

  selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);

  var result:SQLResult = selectStmt.getResult();

  resultsGrid.dataProvider = new DataProvider(result.data);

// var numRows:int = result.data.length;

// for (var i:int = 0; i < numRows; i++)

// {

// var output:String = "";

// for (var prop:String in result.data)

// {

// output += prop + ": " + result.data[prop] + "; ";

// }

// trace("row[" + i.toString() + "]\t", output);

// }

}

function selectError(event:SQLErrorEvent):void

{

  status.text = "Error loading data";

  selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);

  selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);

  trace("SELECT error:", event.error);

  trace("event.error.message:", event.error.message);

  trace("event.error.details:", event.error.details);

}

And i want to add data using text field

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015

Nvm it kglad. i already do it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2015 Apr 30, 2015
LATEST

Oops. I have a problem when i close the application all the data that i add is not been save.

here is my code for save:

function saveData(event:MouseEvent):void

{

  status.text = "Saving data";

  insertStmt = new SQLStatement();

  insertStmt.sqlConnection = conn;

  var sql:String = "INSERT INTO employees (firstName, lastName, salary) VALUES (:param, :param1, :param2)";

  insertStmt.text = sql;

  insertStmt.parameters[":param"] = firstName.text;

  insertStmt.parameters[":param1"] = lastName.text;

  insertStmt.parameters[":param2"] = salary.text;

  insertStmt.addEventListener(SQLEvent.RESULT, insertResult);

  insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError);

  insertStmt.execute();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines