Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
My Carrier: o2 (de)

Clipboard / Copy&Paste

Hi guys,

 

someone already had a question pointing in a similar direcion here: http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Copy-and-paste/m-p/629405, but unluckily the answer wasn't clear (enough for me).

 

I'd like to know if

 

  • there is or will be any mechanism to have content copied to the clipboard upon a button press.
  • copy & paste will be possible from all kinds of elements (e.g. Label) or only editable fields

 

- - -
My approved apps @ App World
Highlighted
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Clipboard / Copy&Paste

Hey,

Currently the only "copy and paste" available is non-native based. That means its not real copy and paste where u can switch to ur email copy something and then switch back to ur app and paste. We've done a few tests and found that there are security protocols in place that prevent pasting from the system clipboard. RIM has stated that it will be possible and they are working on it.
J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
Posts: 27
Registered: ‎03-05-2011
My Device: Blackberry Torch 9800, Playbook Simulator
My Carrier: TELUS

Re: Clipboard / Copy&Paste

[ Edited ]

Is there any more information on this topic yet?

 

Also,

 

which is the way to use the clipboard?  I'm more familiar with the System.setClipboard method but have just read about the Clipboard class...

squivo
Developer
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: Clipboard / Copy&Paste

Hi,

 

   Here are a pair of programs I got off an Adobe website someplace around January which demonstrate how to use the system clipboard.  I tested them with the latest simulator (0.9.4) and they work with the UI buttons as well.

 

Harry

    public class clip1 extends Sprite
    {
        public function clip1()
        {
            var sally:String = "Sally";
            var person:String;

            copy(sally);
            //person = paste();
            //trace(person); //traces: "Sally"
	stage.nativeWindow.visible = true;
        }

        private function copy(text:String):void{
            Clipboard.generalClipboard.clear();
            Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, text);
        }

        private function paste():String{
            if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){
                return String(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
            } else {return null;}
        }

    }

 

 

    public class clip2 extends Sprite
    {
        public function clip2()
        {
	var person:String;
	var nameLabel:Label = new Label();
	var C_format:TextFormat = new TextFormat();

	C_format.align = TextFormatAlign.RIGHT;
	C_format.font = "Verdana";
	C_format.color = 0xffffff;
	C_format.bold = true;
	C_format.size = 36;
	nameLabel.height = 48;
	nameLabel.width = 459;
	nameLabel.format = C_format;
	nameLabel.x = 6;
	nameLabel.y = 6;
	nameLabel.text = "no paste";
	addChild(nameLabel);

	person = paste();

	nameLabel.text = person;
	stage.nativeWindow.visible = true;
        }

        private function copy(text:String):void{
            Clipboard.generalClipboard.clear();
            Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, text);
        }

        private function paste():String{
            if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){
                return String(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
            } else {return null;}
        }

    }

 

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Clipboard / Copy&Paste

@harry: very cool -- thanks for that bit of code it'll def help a lot of people get to where they wanna go Smiley Happy

 

im also excited that the PB will include this feature right off the bat and not have to wait for software updates like some of the competition. Glad to see the "little" things were worked on and included!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
Posts: 27
Registered: ‎03-05-2011
My Device: Blackberry Torch 9800, Playbook Simulator
My Carrier: TELUS

Re: Clipboard / Copy&Paste

Oh Sweet!  White on Rice!  Let you now how that goes for me as my app dpends almost  enitrely on the Clipboard.

squivo
Contributor
Posts: 27
Registered: ‎03-05-2011
My Device: Blackberry Torch 9800, Playbook Simulator
My Carrier: TELUS

Re: Clipboard / Copy&Paste

This works great.  Although I can't seem find a mechanism to paste from the keyboard or in any menus I'm assuming there will be one? Here's how I know it worked:

(I didn't need a whole class so I just borrowed the functions)

 

//copyToClipBoard
private function copyToClipboard(text:String):void{
    
Clipboard.generalClipboard.clear(); Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, text, false);
if(confirmCopy()){ setConfirmationTime(); showConfirmation(true); } else{ showConfirmation(false); } } //pasteFromClipboard private function pasteFromClipboard():String{
if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){ return String(Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT));
} else {return null;} } //confirmCopy private function confirmCopy():Boolean{ var str=pasteFromClipboard(); if(str!=null && str!=''){ return true; } else{ return false; } }

 

 

 

squivo