Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-10-2012, 11:43 PM   #1
ICTShannon
Registered User
 
Join Date: Apr 2012
Posts: 1
Default Convert [object Object] to String in AS3

I am building a small mobile app using the Adobe Flash Builder Launch Pad tool which generates sample code for you.

So what I've done is had it create a simple database example.

What THAT! does is, you enter some string value into an input field and click a button and when you do, a bunch of SQL is executed that creates a table (if it does not exist), inserts the record into a local table and then automatically retrieves that inserted value and loads it as the dataProvider to a list component.

Works great!

HOWEVER!!!....when experimenting with that...I want to pull the data from the local .db it creates/inserts into and load that value into a string, perhaps the ".text" property of an inputText field.

So I've tried a bunch of different things to do this. I've tried clicking on the list item it automtically adds to and retrieving the .selectedItem valiue.

I've tried storing the SQL-retrieved value into an ArrayCollection and then retrieving the value at using ArrayCollectionName.getItemAt(0).toString();

No matter what I do, it comes back into my String variable as [Object object]



But there should be SOME WAY! for me to pull the value the user entered, which was written to the local .db, and put it into a String variable. Right? This seems like a very basic thing to do and in fact I routinely do this in PHP...I just cannot make it work with ActionScript in Flash Builder.

Can someone please show me how to retrieve the string value from the local .db?

I'm open to any solution. Once I see how to do it in one way, I will be able to understand how to do it any other way, I think.

Below is the code sample that the Adobe Launch Pad tool generates as well as an example of how I try to get that value to put into a string variable.

Thank you!

================================================== ======================
The first three functions are what Launch Pad created for me and they work to load the value the user enters into a TextInput filed into the local .db and then reads it from the local .db and loads that into the dataProvider for the list.

At the bottom is my attempt to get the .db value and put it into a simple TextInput string field.


=======================
protected function view1_viewActivateHandler(event:ViewNavigatorEvent ):void
{
sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirector y.resolvePath("giberish.db"));
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = "CREATE TABLE IF NOT EXISTS giberish (label TEXT)";
stmt.execute();
getAllGiberish();
}

protected function getAllGiberish():void
{
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = "SELECT label FROM giberish";
stmt.execute();
list1.dataProvider = new ArrayCollection(stmt.getResult().data);
}

protected function onAdd():void
{
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = "INSERT into giberish values(:giberish)";
stmt.parameters[":giberish"] = g.text;
stmt.execute();
getAllGiberish();
g.text = "";
}

==================== All of the above works!==================

Here is how I try to pull the value into a String. Note: lb2.text is a TextInput field.

list2.dataProvider = new ArrayCollection(stmt.getResult().data);

lb2.text = String(list2.dataProvider.getItemAt(0));

// That puts [Object object] into lb2.text rather than the value of, say, "data_Input_By_Me"
ICTShannon is offline   Reply With Quote
Old 04-11-2012, 12:33 AM   #2
OmerHassan
Senior Member
 
Join Date: Mar 2009
Location: Islamabad, Pakistan
Posts: 207
Send a message via Skype™ to OmerHassan
Default

If you want to access the value of a field in the result set, you'll have to do so by accessing a property of each row of the result set. Have a look at this: http://help.adobe.com/en_US/FlashPla...sult.html#data

Your data provider is a collection of objects. The label property of those objects contains the value of label field.
OmerHassan is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:55 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.