Archive for February, 2010

14
Feb
10

Clipboard Copy And Paste in Flex web Application

Sometime we may  need to access clipboard data for our Applications. In flex we can easily save our data to System clipboard by using System.setClipboard() method. For security reasons getting clipboard data from flex code is not allowed.

An alternate way to get the clipboard data to flex Application is through java script by ExternalInterface.call(). Once control was transferred to javaScript we can access the clipboard data and return it to flex Application. below is the attached code

CopyAndPaste.mxml

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml ” layout=”absolute”>
<mx:TextArea id=”copyData” x=”70″ y=”96″ width=”272″ height=”65″/>
<mx:TextArea id=”pasteData” x=”70″ y=”195″ width=”272″ height=”65″/>
<mx:Button x=”417″ y=”118″ label=”Copy To Clipboard” width=”126″  click=”CopyToClipboard()”/>
<mx:Button x=”417″ y=”213″ label=”Paste From Clipboard” width=”126″ click=”PasteFromClipboard()”/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function CopyToClipboard():void{
System.setClipboard(copyData.text);
}

public function PasteFromClipboard():void{
var str2:String=ExternalInterface.call("PasteFromClipboard");
pasteData.text=str2;
}
]]>
</mx:Script>
</mx:Application>

In index.template.html (flex generated html wrapper ) place the following code inside <script> . . . </script>

function PasteFromClipboard()
{
var str=”"
var browser=navigator.appName;
if(browser==”Microsoft Internet Explorer”)
{
return (window.clipboardData.getData(‘Text’));
}
else if (window.netscape)
{
netscape.security.PrivilegeManager.enablePrivilege( ‘UniversalXPConnect’ );
this.clipboardid = Components.interfaces.nsIClipboard;
this.clipboard = Components.classes['@mozilla.org/widget/clipboard;1'].getService( this.clipboardid );
this.clipboardstring = Components.classes['@mozilla.org/supports-string;1'].createInstance( Components.interfaces.nsISupportsString );
netscape.security.PrivilegeManager.enablePrivilege( ‘UniversalXPConnect’ );
var transfer = Components.classes['@mozilla.org/widget/transferable;1'].createInstance( Components.interfaces.nsITransferable );
transfer.addDataFlavor( ‘text/unicode’ );
this.clipboard.getData( transfer, this.clipboardid.kGlobalClipboard );
var str = new Object();
var strLength = new Object();
transfer.getTransferData( ‘text/unicode’, str, strLength );
str = str.value.QueryInterface( Components.interfaces.nsISupportsString );
return str+”";
}
}

Note : The above program will work only in Internet explorer and morzilla firefox

copy to clipboard flex
05
Feb
10

Way to find Flash Debugger was installed in the system

    Some times we may not be sure whether normal flash player or Flash player debugger version was installed in our system. Flash Debugger version was required for Flash tracer, flex profiler and to capture run time flash errors

The Simple way to confirm that flash debugger version was installed in you system is by right click on a Launched SWF file in the browser and you should get the following Option as shown below


Flash Debugger Options




Follow

Get every new post delivered to your Inbox.