Solved

How to convert  OBJECT to String instead of [object Object] in ActionScript

Posted on 2012-04-07
6
636 Views
Last Modified: 2012-04-16
Hi,

 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]

This makes sense if you look at the bottom of this page where it shows what happens when you cast an Object to a String:  http://tinyurl.com/24cbhxt .

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.applicationStorageDirectory.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"
0
Comment
Question by:TURBOSHAN
  • 4
  • 2
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37827166
Is PHP in play here?  If so, you can use the PHP function var_dump() to visualize the object.  You may be able to call the __toString() method on the object.
http://php.net/manual/en/language.oop5.magic.php
0
 

Author Comment

by:TURBOSHAN
ID: 37829959
No,  I just mentioned that I am able to do this with PHP very easily.

This is a Flash Builder 4.6/Actionscript problem only.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37830542
OK, understood.  I only saw it because it was in the PHP Zone.  Best of luck, ~Ray
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:TURBOSHAN
ID: 37830567
Yeah...there's not a good area for just Flash Builder/Flex/ActionScript on Experts-Exchange so it's always a challenge trying to figure out where to post such questions.

Thanks anyway!
0
 

Accepted Solution

by:
TURBOSHAN earned 0 total points
ID: 37835835
I figured this out!

Use the ObjectUtil class!  It was so easy!  :-)
0
 

Author Closing Comment

by:TURBOSHAN
ID: 37850403
I found my own solution.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now