Share on Google+Share on Google+

Object representation in to String example

Advertisement
We can represent any kind of object in the form of string. For this purpose we have used toString() method for any kind of object.

Object representation in to String example:-

We can represent any kind of object in the form of string. For this purpose we have used toString() method for any kind of object. User can see that process in this example.

Example:-

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init();">

<fx:Script>

<![CDATA[

import flashx.textLayout.formats.Float;

private function init():void{

var num:Number = 97.32;

var bool:Boolean = true;

var currdate:Date = new Date();

myText1.text = num.toString();

myText2.text = bool.toString();

myText3.text = currdate.toString();

}

]]>

</fx:Script>

<s:Panel width="210" height="110" title="Convert other object to String" backgroundColor="0x81B5AA">

<s:VGroup>

<mx:Text id="myText1"/>

<mx:Text id="myText2"/>

<mx:Text id="myText3"/>

</s:VGroup>

</s:Panel>

</s:Application>

In this example we have created three objects that's types is Number, Boolean, Date. We have used toString() method to represent these objects in to string.

Output:-

Download this code

Advertisements

Advertisement

Posted on: June 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.