How i can copy text to the clipboard?

Silux

  • Posts: 438
I made a little text game, and i'd like to add a feature that, hitting a key, it copies a text to the user clipboard, so that the player can paste the text generated.
Currently working at:
Starwarrior 2097(my main project)
How to make successful games in Kongregate and the world(article)

Derelikt

  • Posts: 92
Instead of copying and pasting to the clipboard, you can create a text attribute and set it to the wanted text when the specified button is hit.

Silux

  • Posts: 438
But i'd want the text to be exported outside the game!
So that the user can later paste the text where he wants.
Currently working at:
Starwarrior 2097(my main project)
How to make successful games in Kongregate and the world(article)

Ryusui

  • Posts: 827
It's not the prettiest way, but try this.

Create a Code behavior with both Name and Classname "Clipboard". Replace the sample code given with this:

Code: [Select]
package scripts
{
import flash.system.System

public dynamic class Clipboard
{
public function Clipboard()
{

}

public static function copyToClipboard(string:String = "")
{
System.setClipboard(string);
}
}
}

Now, whenever you want to copy text to the clipboard, you can use a code block like this:

Code: [Select]
Clipboard.copyToClipboard(_stringToCopy);
Or you can pretty it up with a Global Custom Block. It's your call; whichever's most convenient.
In the event of a firestorm, the salad bar will remain open.

Silux

  • Posts: 438
the code should be attached to an actor or to a scene?

Also the code in the attachment doesn't work (gives a parameter number error:Clipboard(). It was expected 0, it has been provided 2.)


Currently working at:
Starwarrior 2097(my main project)
How to make successful games in Kongregate and the world(article)

QwertyB

  • Posts: 52
Anyone nailed this? I've tried using the above text in a (scene attached) code behavior but it just crashes on startup.

QwertyB

  • Posts: 52
(This is what I'm getting)

Quote
ArgumentError: Error #1063: Argument count mismatch on scripts::Clipboard(). Expected 0, got 2.
   at stencyl.api.engine.behavior::Behavior/initScript()

Photon

  • Posts: 2697
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

QwertyB

  • Posts: 52
This was just recently asked:

http://community.stencyl.com/index.php/topic,24056.0.html

From what I can see in that thread, they're talking about copying and pasting to a simulated clipboard within the Stencyl game, rather than copying a text string from the game to the OS's clipboard outside of the game?

Tuo

  • *
  • Posts: 2469
The thread is about a textbox coding for a general copy/paste that can go to anywhere you want. It's not just inside of Stencyl (although I warn up front that it's a bit of a challenge to use it, even with the comments I put in it).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

QwertyB

  • Posts: 52
The thread is about a textbox coding for a general copy/paste that can go to anywhere you want. It's not just inside of Stencyl (although I warn up front that it's a bit of a challenge to use it, even with the comments I put in it).

Thanks for your help Tuo; anything that involves custom code is challenging to me at this point, but I guess I need that. I'm making a "battle rap generator" so only really looking to export text out of the Flash game... I won't even ask about converting it into a tweet, haha.

Tuo

  • *
  • Posts: 2469
If you catch me on my livestream, I can try to show you how to implement it (although will need your game file too).
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)