Wednesday, November 9, 2011

Splitting strings in action script.

I used the following code to split the string in my code:

var lv_string:String;
lv_string = "[RC=200] URL http://www.google.com called successfully";
var lt_string:Array = lv_string.split("URL");
lv_string = lt_string[1];
lt_string = lv_string.split(" ");

Within the bracket we can specify the delimiter on the basis of which we split the string and put it in an array. We can access the value from the array. ie. lt_string[1] to access the url, etc.

Hope this will save some trouble.
To launch to a new window with the url from the advanced data grid control, using
navigateToURL.


navigateToURL(request:URLRequest, window:String):void

The request argument is a URLRequest object that specifies the destination. The window argument specifies whether to launch a new browser window or load the new URL into the current window. The following table describes the valid values for the window argument:

_self:
Specifies the current frame in the current window.

_blank:
Specifies a new window. This new window acts as a pop-up window in the client’s browser, so you must be aware that a pop-up blocker could prevent it from loading.

_parent: Specifies the parent of the current frame.

_top: Specifies the top-level frame in the current window.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;

protected function remove_watermark():void
{
//test.removeChildAt(test.numChildren-1);
(test.getChildAt(test.numChildren-1) as TextField).htmlText = " ";
}
protected function navigate():void
{
if( test.selectedItem.Album != null )
{
var urlRequest:URLRequest = new URLRequest(test.selectedItem.Album.toString());
navigateToURL(urlRequest,”_parent”);
}

]]>
</mx:Script>
<!-- <mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/sap.png")]
public var sapicon:Class;
]]>
</mx:Script>-->
<mx:AdvancedDataGrid id="test" creationComplete="remove_watermark()">
<mx:dataProvider>
<mx:Object Artist="Jlo" Price="60" Album="enchanted"/>
<mx:Object Artist="Shakira" Price="90" Album="woddoo"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Album"/>
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
</mx:AdvancedDataGrid>

</mx:Application>
}

<mx:AdvancedDataGrid id="test" creationComplete="remove_watermark()"itemClick=”navigate”>
<mx:dataProvider>
<mx:Object Artist="Jlo" Price="60" Album="http://www.google.com"/>
<mx:Object Artist="Shakira" Price="90" Album=" http://www.facebook.com"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Album"/>
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
</mx:AdvancedDataGrid>

</mx:Application>

To remove watermark while using Advanced Datagrid control

Code to remove the water mark while using advanced data grid control:



<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;

protected function remove_watermark():void
{
//test.removeChildAt(test.numChildren-1);
(test.getChildAt(test.numChildren-1) as TextField).htmlText = " ";
}

]]>
</mx:Script>
<!-- <mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/sap.png")]
public var sapicon:Class;
]]>
</mx:Script>-->
<mx:AdvancedDataGrid id="test" creationComplete="remove_watermark()">
<mx:dataProvider>
<mx:Object Artist="Jlo" Price="60" Album="enchanted"/>
<mx:Object Artist="Shakira" Price="90" Album="woddoo"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Album"/>
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
</mx:AdvancedDataGrid>

</mx:Application>
}

<mx:AdvancedDataGrid id="test" creationComplete="remove_watermark()">
<mx:dataProvider>
<mx:Object Artist="Jlo" Price="60" Album="enchanted"/>
<mx:Object Artist="Shakira" Price="90" Album="woddoo"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Album"/>
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
</mx:AdvancedDataGrid>

</mx:Application>